This is not an answer but an expanded example:
class TestAwaitTests: XCTestCase {
struct Thing {
let value = true
func doSomething() async throws -> Int? {
try await Task.sleep(nanoseconds: 5_000_000_000)
return 1
}
}
func validation(thing: Thing, file: StaticString = #file, line: UInt = #line) {
XCTAssertFalse(thing.value)
XCTAssertTrue(thing.value) // Breakpoint here
}
func testTest() async throws {
continueAfterFailure = false
let thing = Thing()
let result = try await thing.doSomething()
print("print 1")
XCTAssertNil(result)
print("print 2")
XCTAssertNotNil(result)
print("print 3")
validation(thing: thing)
enum Err: Error { case oops }
throw Err.oops
print("print 4")
}
}
Results in the console output
print 1
print 2
print 3
The test fails, as expected. What is unexpected is that the statements print 2 and print 3 are produced. The line marked Breakpoint here should never execute. I can see it hit even in the debugger continueAfterFailure should be stopping the test first assertion.
Topic:
Programming Languages
SubTopic:
Swift
Tags: