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

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.

主站蜘蛛池模板: 洪雅县| 藁城市| SHOW| 曲松县| 炎陵县| 博客| 靖宇县| 旺苍县| 丰台区| 东乡族自治县| 泗水县| 尉犁县| 宜宾县| 岱山县| 门头沟区| 卢龙县| 达日县| 元朗区| 邵阳县| 贞丰县| 万全县| 白山市| 溧水县| 峡江县| 白银市| 连江县| 清流县| 图们市| 丰顺县| 简阳市| 莎车县| 延安市| 安徽省| 丹凤县| 吉林市| 油尖旺区| 繁昌县| 遂溪县| 祁连县| 洪洞县| 东乡县|