Last active
December 21, 2022 08:24
-
-
Save annjose/1baa75b0796d0d2fef1a10ab74d5bd65 to your computer and use it in GitHub Desktop.
Run unit tests inside Xcode 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
//: [Previous](@previous) | |
import XCTest | |
struct TodoItem { | |
let title: String | |
let dueBy: Date? | |
init(title: String) { | |
self.title = title | |
self.dueBy = nil | |
} | |
} | |
class TodoTests: XCTestCase { | |
override func setUp() { | |
super.setUp() | |
} | |
override func tearDown() { | |
super.tearDown() | |
} | |
func testTodo() { | |
let taskTitle = "finish laundry" | |
let todo = TodoItem(title: taskTitle) | |
XCTAssertEqual(todo.title, taskTitle) | |
} | |
} | |
TodoTests.defaultTestSuite.run() |
Using Xcode 12.5 and gives the error "Cannot find 'XCTAssertEqual' in scope". Is it not supported now?
Using Xcode 12.5 and gives the error "Cannot find 'XCTAssertEqual' in scope". Is it not supported now?
Working fine for me in Xcode 12.5. Make sure you used import XCTest
and make all your classes public if you put them under Sources folder.
Thank you for the example code! I just read John Sundell's article - found it hard to follow... expected more of the classic unit test runner pattern etc.
https://www.swiftbysundell.com/articles/writing-unit-tests-in-a-swift-playground/
It appears that Unit Testing in Playground just happens to work - as opposed to a designed Feature of Playgrounds.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you @tiagomartinho and @RoBo-Inc for the suggestions. Updated the gist 👍