【发布时间】:2017-08-29 17:19:26
【问题描述】:
我正在阅读一本很棒的书,了解 Swift 中的测试驱动开发。我的最终目标是更好地理解 OOP 架构。在我阅读本书时,前面的一节指出,setUp() 方法在我理解的每个测试方法之前被触发,它会设置对象以运行测试以获得通过或失败结果。我不确定的是,从架构的角度来看,这怎么可能? Apple 是如何让一个类的方法在类中的所有其他方法之前被触发的?
这里是一些示例代码:
import XCTest
@testable import FirstDemo
class FirstDemoTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
【问题讨论】:
标签: ios swift oop xctest xctestcase