我正在使用XCTest在我的項目中編寫單元測試,並且在使用XCAssertNil()
或XCAssertNotNil()
方法時,XCTest框架崩潰。XCTestAssertNil由於「無」參數導致崩潰
這裏是我的測試:
XCTAssertNotNil(messageCollection.fieldName, "field_name must be not-nil")
這裏的堆棧跟蹤:
2015-06-22 17:05:17.629 xctest[745:8747] *** Assertion failure in void _XCTFailureHandler(XCTestCase *, BOOL, const char *, NSUInteger, NSString *, NSString *, ...)(), /SourceCache/XCTest_Sim/XCTest-7701/XCTestFramework/OtherSources/XCTestAssertionsImpl.m:41
Test Case '-[Wakanda_iOS_Framework_Tests.WAKAdapterTest testEntityCollectionParsing]' started.
2015-06-22 17:05:17.631 xctest[745:8747] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Parameter "test" must not be nil.'
看來XCTest有一個名爲測試參數不能是零,奇怪預期的方法檢查零(或非零)的值...是否有其他人得到這個問題並解決了它?
我有這個相同的錯誤,但對於不同的情況。我認爲問題在於我濫用測試API - 做異步測試,並在調用'expectation.fulfill()'後嘗試使用'XCTAssertEqual' *。我的猜測是,測試框架沒有注意到真正的問題,然後出現一個看似不相關的原因後來崩潰。 –
是的 - 當你調用'expectation.fulfill()',然後命令一些異步代碼時,'XCTestCase'可能會被卸載。檢查我的答案以下@MattFenwick –