【问题标题】:XCTest Assertion failure in void _XCTFailureHandler(XCTestCase, reason: 'Parameter "test" must not be nil.'XCTest Assertion failure in void _XCTFailureHandler(XCTestCase, reason: 'Parameter "test" must not be nil.'
【发布时间】:2020-07-08 02:41:22
【问题描述】:

单元测试成功后随机报如下错误:

测试套件“选定测试”于 2020-03-27 10:53:02.582 通过。 在 0.005 (0.009) 秒内执行了 4 次测试,0 次失败(0 次意外) 2020-03-27 10:53:02.585302+0530 xctest[66609:1461801] * 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] * 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“参数“test”不得为 nil。 *** 首先抛出调用堆栈: ( 0 核心基础 0x00007fff23c7127e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff513fbb20 ob​​jc_exception_throw + 48 2 核心基础 0x00007fff23c70ff8 +[NSException raise:format:arguments:] + 88 3 基础 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 $s10S程序以退出代码结束:0

有人知道原因吗?我在 Xcode 11.3.1 上运行,没有时间寻找原因,将在几个小时后检查,同时如果有人可以回答将有很大帮助。

【问题讨论】:

    标签: ios objective-c xcode unit-testing xctest


    【解决方案1】:

    自己解决了这个问题。

    原因:这是由于异步闭包/块运行时间稍长并且在测试完成之前没有结束。

    解决方案:修复比在代码流深处找到根本原因要简单得多。通过在测试中添加期望(expectation(description:) ))来解决它,并在异步块完成后通过等待期望 1 秒(waitForExpectations(timeout:, handler:)来实现它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      • 2012-12-04
      • 2018-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多