官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 依兰县| 秦皇岛市| 宁阳县| 西宁市| 镇平县| 招远市| 邵阳县| 韶山市| 昌宁县| 祁连县| 老河口市| 龙山县| 连江县| 大港区| 酉阳| 毕节市| 新宁县| 哈密市| 垫江县| 柘荣县| 乐东| 江城| 武功县| 南城县| 吉木萨尔县| 石泉县| 泰和县| 孟连| 西华县| 赞皇县| 万年县| 屏山县| 毕节市| 星座| 闵行区| 桃江县| 黑山县| 六安市| 花垣县| 醴陵市| 汉川市|