young
(rtSwift)
1
Xcode Version 13.0 beta 4 (13A5201i)
import XCTest
XCTAssertEqual(1.0, 1.5, "This should fail: not equal!") // why this doesn't fail?
print("\nDone")
This just prints "Done". In fact, no XCTxxx call fail.
YOCKOW
(YOCKOW)
2
I guess the test did fail and the failure was just recorded.
XCTAssertEqual calls internally _XCTEvaluateAssertion, and its source is below:
https://github.com/apple/swift-corelibs-xctest/blob/4e351147f582bdc3912f249f361eaba130503029/Sources/XCTest/Public/XCTAssert.swift#L86-L106
young
(rtSwift)
3
So it’s only for use in Xcode test case, not in playground page?
YOCKOW
(YOCKOW)
4
You can do like below. (I also didn't know and did find the answer
)
import XCTest
class PGTest: XCTestCase {
func test_equality() {
XCTAssertEqual(1.0, 1.5, "This should fail: not equal!")
}
}
PGTest.defaultTestSuite.run()
The result would be:
Test Suite 'PGTest' started at 2021-08-10 15:41:38.101
Test Case '-[__lldb_expr_7.PGTest test_equality]' started.
/XCTestWithPG.playground:5: error: -[__lldb_expr_7.PGTest test_equality] : XCTAssertEqual failed: ("1.0") is not equal to ("1.5") - This should fail: not equal!
Test Case '-[__lldb_expr_7.PGTest test_equality]' failed (0.005 seconds).
Test Suite 'PGTest' failed at 2021-08-10 15:41:38.108.
Executed 1 test, with 1 failure (0 unexpected) in 0.005 (0.007) seconds
3 Likes