Skip to content

Instantly share code, notes, and snippets.

@annjose
Last active December 21, 2022 08:24
Show Gist options
  • Save annjose/1baa75b0796d0d2fef1a10ab74d5bd65 to your computer and use it in GitHub Desktop.
Save annjose/1baa75b0796d0d2fef1a10ab74d5bd65 to your computer and use it in GitHub Desktop.
Run unit tests inside Xcode playground
//: [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()
@davidakoontz
Copy link

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