开发者

OCUnit for iPhone App - Set all .m files as part of UnitTest Target

开发者 https://www.devze.com 2023-01-09 15:59 出处:网络
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.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消