我想認爲我理解繼承的想法,但顯然我不這樣做,因爲如果XCTest在其類中提供了安裝方法,我爲什麼會在XCTestCase中有一個設置方法而感到困惑? XCTestCase是XCTest的子類,但在閱讀Apple文檔之後,它們在兩者之間沒有任何區別。爲什麼XCTestCase會覆蓋XCTest的設置方法?
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.
}
}
}
哪種設置方法你在說什麼?從'XCTest'繼承的那個你在你的代碼片段中重寫或從'XCTestCase'繼承的類方法? – dan
@dan我在我的代碼段 –
@dan中重寫了一個,當我看着Apple的引用時,他們(XCTest和XCTestCase)都有這些方法,但它們看起來很相似,或者至少我不能看到Apple的實現 –