nsscreencast / comments

Public comments on NSScreencast.com
0 stars 0 forks source link

Using XCTest in Playgrounds #173

Open subdigital opened 3 years ago

subdigital commented 3 years ago

Written on 03/09/2018 16:19:17

URL: https://nsscreencast.com/episodes/330-using-xctest-in-playgrounds

subdigital commented 3 years ago

originally written by Idris Raja on 06/29/2018 17:36:48

Great Video. I'm trying to use the `TestObserver` in my own tests outside of a playground. How would you use the custom `TestObserver` in a unit test target outside of a playground?

I've tried the following, but I'm not getting the expected messages with the colored emojis. What am I doing wrong?

```
import XCTest
@testable import MyApp

class TestObserver : NSObject, XCTestObservation {
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: Int) {
print("🚫 \(description) line:\(lineNumber)")
}

func testCaseDidFinish(_ testCase: XCTestCase) {
if testCase.testRun?.hasSucceeded == true {
print("✅ \(testCase)")
}
}
}

let observer = TestObserver()
let x = XCTestObservationCenter.shared.addTestObserver(observer)

class MyTest: XCTestCase {
...
```