我正在阅读一本关于Swift中测试驱动开发的书。我的最终目标是更好地理解OOP体系结构。在我读这本书的时候,最早的一节讲述了setUp()方法在每个测试方法之前被触发,我明白做的是设置对象以运行测试以获得通过或失败的结果。我不确定的是,从架构的角度来看,这甚至是可能的?苹果公司如何能够制定出一种在班级中每一种其他方法之前都被解雇的方法?在调用每个测试方法之前,如何调用setUp()方法?
下面是一些示例代码:
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.
}
}
}
谢谢,如果是这种情况,那么我该如何理解UIViewController的方法是如何被触发的?例如,我相信ViewDidLoad()是由运行时环境自动触发的。但是,我们所说的“自动”是指什么,我正在考虑某个地方的某个地方是否调用了这种方法,我想知道在哪里了解更多信息。我希望这是有道理的 –