Reputation: 3052
Randomly getting the following error after completing unit tests successfully :
Test Suite 'Selected tests' passed at 2020-03-27 10:53:02.582. Executed 4 tests, with 0 failures (0 unexpected) in 0.005 (0.009) seconds 2020-03-27 10:53:02.585302+0530 xctest[66609:1461801] * Assertion failure in void _XCTFailureHandler(XCTestCase *__strong _Nonnull, BOOL, const char * _Nonnull, NSUInteger, NSString *__strong _Nonnull, NSString *__strong _Nullable, ...)(), /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-15702/Sources/XCTestFramework/Core/XCTestAssertionsImpl.m:41 2020-03-27 10:53:02.598306+0530 xctest[66609:1461801] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Parameter "test" must not be nil.' *** First throw call stack: ( 0 CoreFoundation 0x00007fff23c7127e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff513fbb20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23c70ff8 +[NSException raise:format:arguments:] + 88 3 Foundation 0x00007fff256e9c1a -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166 4 XCTest 0x000000010285de1f _XCTFailureHandler + 827 5 XCTest 0x000000010285e2bb _XCTPreformattedFailureHandler + 154 6 libXCTestSwiftSupport.dylib 0x000000010aa81c81 $s6XCTest14XCTAssertEqual___4file4lineyxyKXK_xyKXKSSyXKs12StaticStringVSutSQRzlF + 2753 7 ShelfTests 0x0000000104d4aeff $s10SProgram ended with exit code: 0
Anyone knows the reason? I'm running on Xcode 11.3.1, haven't got time to look for the reason, will check couple of hours later, meanwhile if someone can answer would be of great help.
Upvotes: 1
Views: 1122
Reputation: 3052
Resolved the issue myself.
Reason: It was happening due to an asynchronous closure/block was running little longer & not ending before the completion of the tests.
Solution: Fixing was pretty simpler than finding the root cause deep in the code flow. Solved it by adding an expectation (expectation(description:) )
inside the test and fulfilled it once the async block was completed by waiting for the expectation for 1 second (waitForExpectations(timeout:, handler:
).
Upvotes: 1