所以,我有MyViewController的實例在一個UISplitViewController的詳圖。我正在運行單元測試以查看詳細視圖是否包含正確類型的視圖。isKindOfClass:返回單元測試包假陰性
我測試控制器的類型在單元測試使用以下:
[controller isKindOfClass:[MyViewController class]];
然而,isKindOfClass方法總是返回NO
當我PO在調試器我得到以下的對象:
(gdb) po controller
<MyViewController: 0xb31c4d0>
我也曾嘗試isMemberOfClass:方法,得到了相同的結果。任何人都可以解釋爲什麼會發生?
編輯:所以在閱讀Nick Weaver發佈的文章後,我意識到我在測試包的編譯源代碼階段包含了我的應用程序的源代碼文件。這也是在日誌中通過類似的聲明指出以下幾點:
Class MyViewController is implemented in both /Users/jdoe/Library/Application Support/iPhone Simulator/4.3.2/Applications/670A077A-BAD8-4FA6-945A-851F33114CF5/MyApp.app/MyApp and /Users/jdoe/Library/Developer/Xcode/DerivedData/MyApp-drxyfejeattjwgantzesgensnlnx/Build/Products/Debug-iphonesimulator/MyAppTests.octest/MyAppTests. One of the two will be used. Which one is undefined.
然而,當我從測試包的編譯來源刪除源文件建立階段,我會得到看起來像下面的鏈接錯誤:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MyViewController", referenced from:
objc-class-ref in _MyViewControllerTests.o
(maybe you meant: _OBJC_CLASS_$__MyViewControllerTests)
是否在運行時沒有測試這種行爲相同? – 2011-04-22 12:23:58
從我可以看到它不 – nduplessis 2011-04-22 12:26:38