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

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.

主站蜘蛛池模板: 涟源市| 黔西县| 兴海县| 临西县| 永清县| 阆中市| 绥化市| 海原县| 武夷山市| 新平| 长岛县| 边坝县| 永修县| 江川县| 博湖县| 凤台县| 巧家县| 渭南市| 满城县| 漳浦县| 三原县| 陆良县| 施秉县| 济宁市| 武山县| 丹凤县| 渭南市| 太保市| 固原市| 巴楚县| 剑川县| 云浮市| 重庆市| 贵阳市| 习水县| 岳西县| 沾益县| 青阳县| 如东县| 夏河县| 织金县|