Created
May 14, 2018 20:44
-
-
Save ansonj/14eb3c0c69ee5e43a249a32babbcb4ad to your computer and use it in GitHub Desktop.
Run XCTests from inside a Swift Playground
This file contains 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
import XCTest | |
public func runTests(inClass testClass: XCTestCase.Type) { | |
let testSuite = testClass.defaultTestSuite | |
testSuite.run() | |
guard let testRun = testSuite.testRun else { | |
preconditionFailure("Couldn't run tests in \(testClass)") | |
} | |
let failCount = testRun.totalFailureCount | |
guard failCount == 0 else { | |
preconditionFailure("\(testClass) had \(failCount) failures") | |
} | |
} | |
// MARK: - Usage | |
class SampleTestCase: XCTestCase { | |
func testCanary() { | |
XCTAssert(true) | |
} | |
} | |
runTests(inClass: SampleTestCase.self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment