isKindOfClass:在单元测试包中返回false negative [英] isKindOfClass: returns false negative in unit test bundle

查看:431
本文介绍了isKindOfClass:在单元测试包中返回false negative的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在UISplitViewController的详细视图中有一个MyViewController的实例。我正在运行单元测试以查看详细信息视图是否包含正确的视图类型。



我在单元测试中测试控制器的类型如下: p>

  [controller isKindOfClass:[MyViewController class]];但是,isKindOfClass方法总是返回NO 


p>当我在调试器中的对象时,我得到以下:

 (gdb)po控制器
< MyViewController:0xb31c4d0>



我也尝试了isMemberOfClass:方法,它产生相同的结果。



编辑:因此,阅读Nick Weaver发表的文章后,我发现我包含了我的应用程式的来源文件在测试包的编译源代码构建阶段。这也在日志中通过类似以下的语句指示:​​

 类MyViewController实现在/ Users / jdoe /应用程序支持/ iPhone模拟器/ 4.3.2 /应用程序/ 670A077A-BAD8-4FA6-945A-851F33114CF5 / MyApp.app / MyApp和/ Users / jdoe / Library / Developer / Xcode / DerivedData / MyApp-drxyfejeattjwgantzesgensnlnx / Build / -iphonesimulator / MyAppTests.octest / MyAppTests。将使用两者之一。哪一个是未定义的。但是,当我从测试包的编译源构建阶段中删除源文件时,我会得到一个链接器错误,如下所示:

 架构i386的未定义符号:
_OBJC_CLASS _ $ _ MyViewController,引用自:
objc-class-ref in _MyViewControllerTests.o
(也许你的意思是:_OBJC_CLASS _ $ __ MyViewControllerTests)


解决方案

正如我的问题中所提到的,我意识到我在测试包的编译源构建阶段中错误地包含了应用程序的源文件。从此构建阶段删除源文件后,我通过将默认构建隐藏的设置更改为否,解决了缺少的符号的链接器错误。





这解决了链接器错误和意味着我不再包含重复的源文件






注意:此外,请务必设置主机目标 Xcode的 Info 选项卡中的测试目标,因此它将从中提取编译源代码


So I have an instance of MyViewController in the detail view of a UISplitViewController. I am running a unit test to see whether the detail view contains the correct type of view.

I test the type of controller in the unit test with the following:

[controller isKindOfClass:[MyViewController class]];

However, the isKindOfClass method always returns NO

When I po the object in the debugger I get the following:

(gdb) po controller
<MyViewController: 0xb31c4d0>

I have also tried the isMemberOfClass: method, it yields the same results. Can anyone explain why this would happen?

EDIT: So after reading the article posted by Nick Weaver I realised that I was including my app's source files in the test bundle's compile sources build phase. This was also indicated in the log by statements similar to following:

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.

However, when I remove the source files from the test bundle's compile sources build phase, I would get a linker error that looks like the following:

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MyViewController", referenced from:
  objc-class-ref in _MyViewControllerTests.o
 (maybe you meant: _OBJC_CLASS_$__MyViewControllerTests)

解决方案

As mentioned in my question, I realised I was incorrectly including the app's source files in the test bundle's compile sources build phase. After removing the source files from this build phase I solved the linker error of the missing symbols by changing the Symbols Hidden by Default build setting to "No" for the Debug configuration

This solved the linker error and meant that I was no longer including duplicate source files


Note: Also, be sure to set the "Host Target" for the test target in the Info tab of Xcode so it'll pull the compile sources from there

这篇关于isKindOfClass:在单元测试包中返回false negative的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆