Created
January 31, 2019 18:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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