Started on some unit tests today in Xcode and decided to test my test. Turns out they always pass but not sure why.
The following should fail:
struct MyUnitTest {
@Test func example() throws {
XCTAssertTrue("a" == "b")
XCTAssertEqual("a", "b")
}
}
But they don't. Anyone know why?
Started on some unit tests today in Xcode and decided to test my test. Turns out they always pass but not sure why.
The following should fail:
struct MyUnitTest {
@Test func example() throws {
XCTAssertTrue("a" == "b")
XCTAssertEqual("a", "b")
}
}
But they don't. Anyone know why?
Share Improve this question edited 18 hours ago Alexander 63.3k13 gold badges105 silver badges167 bronze badges asked 18 hours ago Rob BonnerRob Bonner 9,4248 gold badges36 silver badges57 bronze badges 3 |1 Answer
Reset to default 0You're using Swift Testing (as indicated by the @Test
and lack of XCTestCase
subclass), which doesn't use XCTest assertions. Instead you'd write:
struct MyUnitTest {
@Test func example() throws {
#expect("a" == "b")
}
}
If you don't need any instance variables on the struct, you can even just have the test functions at the top level without the boilerplate of a struct. The need to wrap all the test cases in a class was a limitation of Objective-C and XCTest, which no longer applies.
@Test
) and XCTest, which I'm not sure is possible like this – Alexander Commented 18 hours ago#expect("a" == "b")
instead of the two XCTest assertions you tried. – Alexander Commented 18 hours ago