2020-04-28a few seconds read (About 56 words)How to assert asynchronously in XCTestIssue #644 123456789101112131415161718192021import XCTestextension XCTestCase { /// Asynchronously assertion func XCTAssertWait( timeout: TimeInterval = 1, _ expression: @escaping () -> Void, _: String = "", file _: StaticString = #file, line _: UInt = #line ) { let expectation = self.expectation(description: #function) DispatchQueue.main.asyncAfter(deadline: .now() + timeout) { expression() expectation.fulfill() } let waiter = XCTWaiter() XCTAssertTrue(waiter.wait(for: [expectation], timeout: timeout + 1) == .completed) }} Updated at 2020-04-28 09:23:59 #swifttesting