-
-
Save annjose/1baa75b0796d0d2fef1a10ab74d5bd65 to your computer and use it in GitHub Desktop.
//: [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() |
Thank you @tiagomartinho and @RoBo-Inc for the suggestions. Updated the gist 👍
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.
And "import Foundation" is unnecessary.