How to run one-time setup code before executing any XCTest

前端 未结 4 785
感情败类
感情败类 2020-12-28 12:52

I have the following problem. I want to execute a piece of code before all test classes are executed. For instance: I don\'t want my game to use the SoundEngine singleton du

4条回答
  •  感情败类
    2020-12-28 13:00

    From Writing Test Classes and Methods:

    You can optionally add customized methods for class setup (+ (void)setUp) and teardown (+ (void)tearDown) as well, which run before and after all of the test methods in the class.

    In Swift that would be class methods:

    override class func setUp() {
        super.setUp()
        // Called once before all tests are run
    }
    
    override class func tearDown() {
        // Called once after all tests are run
        super.tearDown()
    }
    

提交回复
热议问题