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