gpt4 book ai didi

iphone - 无法识别的类别选择器 SenTestCase

转载 作者:太空狗 更新时间:2023-10-30 03:21:16 25 4
gpt4 key购买 nike

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

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

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

然后将适当的导入语句添加到我的测试用例中并编写了以下测试:

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

NSString *actual = [test pluralize];

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

但是,这会导致我的测试崩溃(不是失败),并显示“无法识别的选择器已发送到实例”。

如何测试库中的类别?

我已经压缩并上传了完整的项目 here如果我的描述不充分。

最佳答案

我自己正在寻找这个问题的答案并找到了(我相信)一个更简单的解决方案,它不需要记住在项目中添加新类别类时在编译源列表中添加引用。

在测试目标的build设置中,将 -ObjC 添加到 Linking/Other Linker Flags 值。

可以在 Apple Reference 中找到有关此错误实际发生原因的进一步解释。 .

关于iphone - 无法识别的类别选择器 SenTestCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5465076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com