OCUnit for iPhone App - 将所有 .m 文件设置为 UnitTest Target 的一部分
大家好,
我有两个目标:MyApp 和 UnitTests
MyApp 包含两个类:ClassA 和 ClassB。 ClassA 有一个使用 ClassB 方法的方法“getSomeNumber”。
UnitTest 是一个“单元测试包”,在“组和文件”部分我有一个名为“UnitTests”的文件夹,我在其中创建了一个“ MyAppTest”类。
MyAppTest 类具有以下方法:
-(void)testSomething
{
ClassA *cA = [[ClassA alloc] init];
int x = [cA getSomeNumber];
[cA release];
STAssertEquals(1, x, @"The number is not equal to 1");
}
我导入了“ClassA.h”,现在我需要设置“UnitTest”目标的“ClassA.m”部分。 当我构建时出现错误
**"_OBJC_CLASS_$_ClassB", referenced from:**
所以我需要将“ClassB.m”添加到“UnitTest”taget并且它可以工作。
如果 ClassA 使用 ClassC,而 ClassC 使用了数千个类,会发生什么? 我有这个问题,我需要将数千个类包含到“UnitTest”目标中。
我认为将我的整个 MyApp 项目 包含到 UnitTest 目标中应该是一个更好的解决方案或配置。
谢谢大家! 问候。
Hy everybody,
I have two targets: MyApp and UnitTests
MyApp contains two classes: ClassA and ClassB.
ClassA has a method "getSomeNumber" that uses a ClassB method.
UnitTest is a "Unit Test Bundle" and in "Groups & Files" section i have a folder named "UnitTests" where i create a "MyAppTest" Class.
MyAppTest Class has the following method:
-(void)testSomething
{
ClassA *cA = [[ClassA alloc] init];
int x = [cA getSomeNumber];
[cA release];
STAssertEquals(1, x, @"The number is not equal to 1");
}
I imported the "ClassA.h" and now i need to set "ClassA.m" part of "UnitTest" target.
When i build i have the error
**"_OBJC_CLASS_$_ClassB", referenced from:**
So i need to add "ClassB.m" to "UnitTest" taget and it Works.
What happens if ClassA uses ClassC that uses thousands of classes?
I have this problem and i need to include thousand of class to the "UnitTest" Target.
I think it sould be a better solution or configuration to include my whole MyApp project into UnitTest target.
Thank you all!
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您依赖于数千个类,我建议您将这些类组织到可以重用的库中。这样,您可以将目标(用于测试或其他)链接到单个库,而不是包含大量单独的代码文件。
如果您的目标是 iOS 设备,则需要创建静态库,因为在设备上无法动态链接到自定义库。
If you have dependencies on thousands of classes, I would suggest you organize those classes into libraries that you can reuse. That way, you can link targets (for testing or otherwise) against a single library, rather than including lots of individual code files.
If you're targeting an iOS device you'll need to create static libraries, since dynamic linking to custom libraries is not possible on devices.