我正在阅读一本很棒的书,了解 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.
}
}
}