Skip to content

Instantly share code, notes, and snippets.

@ansonj
Created May 14, 2018 20:44
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 ansonj/14eb3c0c69ee5e43a249a32babbcb4ad to your computer and use it in GitHub Desktop.
Save ansonj/14eb3c0c69ee5e43a249a32babbcb4ad to your computer and use it in GitHub Desktop.
Run XCTests from inside a Swift Playground
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