Created
December 14, 2016 21:10
-
-
Save BrandonShega/dfe3f51107efab54f3b011486b82a4f2 to your computer and use it in GitHub Desktop.
Playground TDD
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
import XCTest | |
class PlaygroundTestObserver: NSObject, XCTestObservation { | |
@objc func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) { | |
print("Test failed on line \(lineNumber): \(testCase.name), \(description)") | |
} | |
} | |
struct TestRunner { | |
func runTests(testClass: AnyClass) { | |
print("Running test suite \(testClass)") | |
let tests = testClass as! XCTestCase.Type | |
let testSuite = tests.defaultTestSuite() | |
testSuite.run() | |
let run = testSuite.testRun as! XCTestSuiteRun | |
print("Ran \(run.executionCount) tests in \(run.testDuration) with \(run.totalFailureCount) failures") | |
} | |
} | |
class ExampleTests: XCTestCase { | |
func testShouldFail() { | |
XCTFail("This will fail") | |
} | |
func testShouldPass() { | |
XCTAssertEqual(1,1) | |
} | |
} | |
let observer = PlaygroundTestObserver() | |
let center = XCTestObservationCenter.shared() | |
center.addTestObserver(observer) | |
TestRunner().runTests(testClass: ExampleTests.self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment