Skip to content

Instantly share code, notes, and snippets.

@mcmurrym
Created January 31, 2019 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcmurrym/78f62531c31647f243e743f9d5a51039 to your computer and use it in GitHub Desktop.
Save mcmurrym/78f62531c31647f243e743f9d5a51039 to your computer and use it in GitHub Desktop.
Repeat a test till it fails. This can be used to help troubleshoot tests with intermittent failures and to grow confidence in the code being tested or the test itself, being fixed
#!/usr/bin/swift
import Foundation
class TestRepeater {
func runTest() {
let result = shell("/usr/bin/xcodebuild", [
"-project", "PSKit.xcodeproj",
"-scheme", "PSKit",
"test-without-building",
"-only-testing:PSKitTests/CommonModelSingletonRequestStoreTests/testGetPublishWhenOpCompletes_twoOps",
"-destination", "platform=iOS Simulator,name=iPhone XR",
])
let stringResult = String(describing: result)
if stringResult.contains("TEST EXECUTE SUCCEEDED") {
runTest()
} else {
print(stringResult)
}
}
func shell(_ launchPath: String, _ arguments: [String]) -> String? {
let task = Process()
task.launchPath = launchPath
task.arguments = arguments
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)
return output
}
}
let testRepeater = TestRepeater()
testRepeater.runTest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment