我知道一个类是未来对象的蓝图,我正在尝试使用 Swift 更好地掌握 OOP 架构。所以我的问题是,从类和实例的角度运行测试时会发生什么过程。我认为我实际上并没有必要创建我的 XCTestCase 子类的实例,但 Xcode 似乎会自动执行此操作。当我正在构建更多激情项目应用程序时,我通常必须创建一个实例才能使用它,但在测试中我没有那种感觉,它只是通过点击 (Command + U) 来工作。我想了解是否甚至创建了一个实例,如果是这样,如何创建?
这是蓝图 XCTestCase 子类的一些示例代码,但我不必实际实例化此类:
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.
}
}
}