In Xcode Playground, why `XCTAssertEqual(1.0, 1.5, "This should fail: not equal!")` doesn't fail?

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.

I guess the test did fail and the failure was just recorded.

XCTAssertEqual calls internally _XCTEvaluateAssertion, and its source is below:

So it’s only for use in Xcode test case, not in playground page?

You can do like below. (I also didn't know and did find the answer:sweat_smile:)

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
Terms of Service

Privacy Policy

Cookie Policy