[英]Using OCMock 1.77 for Unit and Application Test with iOS4 and Xcode 4/SDK4.3
我正在嘗試使用OCMock 1.77進行iOS4和Xcode 4 / SDK4.3的單元和應用程序測試。 我按照說明使用OCMock作為靜態庫,在這里找到: http : //www.mulle-kybernetik.com/software/OCMock/ 。 沒有OCMock,單元和應用程序測試運行良好。
當我添加OCMock並嘗試運行OCMock的模擬器測試套件(單元測試)時,我的測試裝置崩潰了代碼134.測試裝置運行良好的設備(應用程序測試)。 如果我查看控制台,我會看到下面的消息 - 這表明我沒有按照上述URL中的說明添加-force_load鏈接器標志。 但我有......有什么想法嗎?
我看了一下: 測試裝置在iOS 4上使用OCMock驗證代碼134異常退出,這表明這種行為是一個錯誤 - 但我不確定它是否與我運行OCMock測試套件的情況相同。 如果它是一個bug,有沒有辦法在單元測試中使用模擬?
TIA。
=====
控制台輸出:
3/30/11 1:02:32 AM otest[38552] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '** Expected method not present; the method getArgumentAtIndexAsObject: is not implemented by NSInvocation. If you see this exception it is likely that you are using the static library version of OCMock and your project is not configured correctly to load categories from static libraries. Did you forget to add the -force_load linker flag?'
*** Call stack at first throw:
(
0 CoreFoundation 0x004a05a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x002cf313 objc_exception_throw + 44
2 CoreFoundation 0x00458ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x00458e6a +[NSException raise:format:] + 58
4 LogicTests 0x00f89de4 +[OCMockObject initialize] + 115
5 libobjc.A.dylib 0x002cfd9b _class_initialize + 380
6 libobjc.A.dylib 0x002d773f prepareForMethodLookup + 73
7 libobjc.A.dylib 0x002ce069 lookUpMethod + 86
8 libobjc.A.dylib 0x002ce1d6 _class_lookupMethodAndLoadCache + 40
9 libobjc.A.dylib 0x002e10e3 objc_msgSend + 87
10 SenTestingKit 0x20108824 +[NSObject(SenTestRuntimeUtilities) senAllSubclasses] + 107
11 SenTestingKit 0x201074a7 +[SenTestSuite updateCache] + 39
12 SenTestingKit 0x20107443 +[SenTestSuite suiteForBundleCache] + 92
13 SenTestingKit 0x201073a4 +[SenTestSuite testSuiteForBundlePath:] + 108
14 SenTestingKit 0x2010606b +[SenTestProbe specifiedTestSuite] + 332
15 SenTestingKit 0x20106792 +[SenTestProbe runTests:] + 156
16 otest 0x000023c7 0x0 + 9159
17 otest 0x000025f2 0x0 + 9714
18 otest 0x0000209a 0x0 + 8346
19 otest 0x00002049 0x0 + 8265
)
一切都應該正常工作。 要驗證:
#import <OCMock/OCMock.h>
// simple test to ensure building, linking,
// and running test case works in the project
- (void)testOCMockPass {
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:@"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
STAssertEqualObjects(@"mocktest", returnValue, @"Should have returned the expected string.");
}
- (void)testOCMockFail {
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:@"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
STAssertEqualObjects(@"thisIsTheWrongValueToCheck", returnValue, @"Should have returned the expected string.");
}
非常感謝:
恩里科博塔尼
我可以通過刪除-force_load標志來重現這一點。 檢查以確保它已設置在測試目標上,而不是主目標上,並且它指向靜態庫的正確位置。 就我而言,就是這樣
-force_load $(PROJECT_DIR)/Libraries/libOCMock.a
您鏈接的另一個SO問題只是說當mock的verify
方法失敗時,它會從NSInvocation上的類別方法拋出異常,這會導致otest崩潰。 它仍然有效; 消息比斷言失敗更加神秘,XCode將其標記為測試類中的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.