Can I run an XCTest suite multiple times?

前端 未结 6 1660
盖世英雄少女心
盖世英雄少女心 2021-01-12 05:37

Is it possible to have Xcode run your unit tests multiple times?

I had an issue in several unit tests that caused intermittent failures. Now that I think I\

6条回答
  •  醉梦人生
    2021-01-12 06:29

    Try using a for loop:

    func testMultiple() {
        for _ in 0...100 {
                ...
                XCTAssert(errMessage == nil, "no error expected")        
        }
    }
    

    Note this doesn't work within a self.measureBlock(). You'll get an NSInternalConsistencyException: Cannot measure metrics while already measuring metrics

    However, you can CALL this within a measureBlock():

    func testMultiple() {
        for _ in 0...100 {
                ...
                XCTAssert(errMessage == nil, "no error expected")        
        }
    }
    
    func testPerformance() {
        self.measureBlock() {
            self.testMultiple()
        }
    }
    

    Xcode 8 runs the measureBlock code 10 times.

提交回复
热议问题