Cos*_*ows 2 ios xctest swift xctestcase
我想以为我了解继承的概念,但是显然我不明白,因为如果XCTest在其类中提供设置方法,为什么在XCTestCase中存在设置方法,我感到困惑。XCTestCase是XCTest的子类,但是在阅读了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.
        }
    }
}
XCTest是一个基类,具有空setUp()和tearDown()方法。
XCTestCase继承自XCTest,因此它继承了相同的方法。它没有自己的实现。无论如何,它们只是无能为力的方法。仅定义它们,以便我们可以覆盖它们。这是“ 模板方法”设计模式的示例。
为什么要在XCTest中定义这些方法,或者根本没有XCTest?测试运行程序可以使用XCTest的所有子类,并且对XCTestCase一无所知。这可能使我们可以定义除XCTestCase子类以外的其他测试套件的新方法,同时仍与XCTest框架集成。
有关xUnit架构的更多信息,请参见JUnit:库克之旅
| 归档时间: | 
 | 
| 查看次数: | 1076 次 | 
| 最近记录: |