- Test-Driven iOS Development with Swift 4(Third Edition)
- Dr. Dominik Hauser
- 122字
- 2021-07-02 15:39:40
Refactor - example 1
Before writing more tests, we need to refactor the existing ones. In the production code, there is nothing to refactor. This code couldn't be simpler or more elegant. In the test case, we now have two test methods. Both start by creating an instance of ViewController. This is a repetition of code and a good candidate for refactoring.
Add the following property at the beginning of the FirstDemoTests class:
var viewController: ViewController!
Remember that the setUp() method is called before each test is executed. So, it is the perfect place to initialize the viewController property:
override func setUp() { super.setUp() viewController = ViewController() }
Now, we can remove this let viewController = ViewController() line of code from each test.
推薦閱讀
- Redis Applied Design Patterns
- ASP.NET MVC4框架揭秘
- HoloLens Beginner's Guide
- Learning RxJava
- C語言程序設(shè)計基礎(chǔ)與實(shí)驗(yàn)指導(dǎo)
- Learning ASP.NET Core 2.0
- Python測試開發(fā)入門與實(shí)踐
- C語言程序設(shè)計
- Learning Neo4j 3.x(Second Edition)
- Spring Boot進(jìn)階:原理、實(shí)戰(zhàn)與面試題分析
- Python 3.7從入門到精通(視頻教學(xué)版)
- Practical Maya Programming with Python
- AngularJS UI Development
- 從零開始學(xué)UI設(shè)計·基礎(chǔ)篇
- Zend Framework 2 Cookbook