How to run Xcode test multiple times

iOS lightning blog ⚡️

Thongchai Kolyutsakul
SwiftBlade
Published in
Nov 19, 2023

--

Your first idea may be to use simple for loop like this:

func testMultiple() {
for _ in 0...100 {
XCTAssertEqual(sut.value, 42)
}
}

But don’t do that! Xcode has this feature if you use test plan.

Go to your test plan (xctest) file, under Configurations tab.

  • set Test Repetition Mode to “Up Until Maximum Repetitions”
  • set Maximum Test Repetitions to your desired value. Here I use 10000.

--

--

Thongchai Kolyutsakul
SwiftBlade

iOS developer since 2009. Working @Viki in Singapore. I write about iOS development, Swift language, and general software engineers tips.