- 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.
推薦閱讀
- 極簡算法史:從數學到機器的故事
- Facebook Application Development with Graph API Cookbook
- SOA實踐
- Visual Studio 2012 Cookbook
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- DevOps Automation Cookbook
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優化計算
- 零基礎學Java程序設計
- Reactive Android Programming
- JAVA程序設計實驗教程
- Android開發:從0到1 (清華開發者書庫)
- Instant Lucene.NET
- OpenResty完全開發指南:構建百萬級別并發的Web應用
- Arduino可穿戴設備開發
- QlikView Unlocked