类别的无法识别的选择器SenTestCase [英] Unrecognized Selector SenTestCase for Category

查看:154
本文介绍了类别的无法识别的选择器SenTestCase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XCode 4中创建了一个带有单元测试的新Cocoa Touch静态库项目,并添加了一个类别:

I created a new Cocoa Touch Static Library project with Unit Testing in XCode 4 and added a category:

// NSString+Inflections.h
@interface NSString (Inflections)
- (NSString *)pluralize;
@end

// NSString+Inflections.m
@implementation NSString (Inflections)
- (NSString *)pluralize { return self; }
@end

然后将适当的import语句添加到我的测试用例中, test:

then added the appropriate import statement to my test cases and wrote the following test:

- (void)testPluralize
{
  NSString *test = @"person";
  NSString *expected = @"people";

  NSString *actual = [test pluralize];

  STAssertEqualObjects(actual, expected, @"Whoops"); 
}



发送到实例。

However, this causes my tests to crash (not fail) with 'unrecognized selector sent to instance'.

如何测试库中的类别?

How can I test a category inside a library?

如果我的说明不充分,我已压缩并上传了整个项目此处

I've compressed and uploaded the full project here if my description is inadequate.

推荐答案

我正在寻找一个答案这个问题自己,发现(我相信)一个更简单的解决方案,

I was searching for an answer this problem myself and found (I believe) a simpler solution, which doesn't require remembering to add a reference in the Compile Sources list whenever a new category class is added to the project.

在测试目标的构建设置中,添加 -ObjC 到链接/其他链接器标记值。

In the test target's build settings, add -ObjC to the Linking / Other Linker Flags value.

进一步解释为什么这个错误实际发生可以在应用参考

Further explanation for why this error actually happens can be found at Apple Reference.

这篇关于类别的无法识别的选择器SenTestCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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