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

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.

主站蜘蛛池模板: 平果县| 信宜市| 广南县| 长垣县| 南昌县| 肇源县| 翼城县| 泽库县| 云林县| 五华县| 宝山区| 武夷山市| 扎赉特旗| 东乌| 达州市| 青冈县| 丁青县| 凤台县| 榆林市| 涡阳县| 永福县| 庆阳市| 天津市| 洪泽县| 许昌县| 元阳县| 鄢陵县| 奉化市| 睢宁县| 天津市| 察隅县| 平昌县| 沅陵县| 东安县| 无为县| 鄂伦春自治旗| 平乐县| 泰州市| 冀州市| 台江县| 廉江市|