Automatically run a test case Many times in Xcode

In Xcode, is there a way to run one test case n times automatically?

The reason for this is because some of my beta testers are encountering random crashes in my application. I see crash logs in TestFlight, as well as a stack trace, but I cannot reproduce the crash.

An accident occurs infrequently, but when this happens, it always happens when users try to create a database record, which is then uploaded to the server. The problem with the crash logs is that my code does not appear in their stack trace (all things are UIKit and CoreFoundation - and each time it is different).

My solution is to run a test for this part of the application for 100 seconds, with an exception checkpoint set, to try and cause an error in my dev environment. But I do not know how to do this automatically.

+6
source share
2 answers

There is no such thing in Xcode.

You can create a class XCTestCasethat intercepts the validation methods that it inherits to return multiple runs, but this is usually annoying and mostly undocumented.

Most likely, you will have a “meta test” instead, which repeatedly calls another test method:

func testOnce() {}

func testManyTimes() {
    for _ in 0..<1000 { testOnce() }
}

, /. , , - :

let test = XCTestCase(selector: #selector(testOnce))
test.invokeTest()

XCTest, , , XCTestCaseRun ( ).

+2

invokeTest

override func invokeTest() {
    for time in 0...15 {
        print("this test is invoking: \(time) times")
        super.invokeTest()
    }
}
0

Source: https://habr.com/ru/post/1548158/


All Articles