Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

midntdj

macrumors newbie
Original poster
Sep 23, 2009
9
0
I'm attempting to create some Unit Tests for Logic & Application. I went through the sample program in the Apple Docs and even down loaded the iPhoneUnitTesting project.

What I can't see to figure out or find in any the documentation or samples, is how to include your own classes / methods into the Unit test file and get it to link correctly.

I have a class that sets up data for a picker, and I want to just verify that the data is populated correctly and it matches the code that is expected.

But when I include the .h file in one of my Unit Test files, I get a linking error during the build. "_OBJC_CLASS_$_MyClass", referenced from: _objc_classrefs_DATA@0 in MyClassTest.o Symbol(s) not found.

I'm sure it's just something in the Unit Test setup that I'm missing.

I created/copied my target app and renamed it "MyAppTesting".
I added my TestBundle to MyAppTesting as a dependency.
My TestBundle contains the compiled tests sources
And I verified that the target: MyAppTesting contains the Include file of the Class I'm attempting to use in it's Compile Sources.

Any help would be grateful.
 
If you click get info on your class source file and check the targets, you're sure it is set to link to all relevant targets?
 
Is there any solution?

I have same problem.

In "Xcode Unit Testing Guide" I found instruction to set "Bundle Loader" and "Test Host" of Test Bundle target (http://developer.apple.com/mac/libr....html#//apple_ref/doc/uid/TP40002171-CJBIHGEI)

But value is wrong, and to resolve this problem must set "$(CONFIGURATION_BUILD_DIR)/MyApp.app/MyApp".

But linker error is not resolved.

Who know how correctly setting up Unit Test.

Unfortunately whilst integrated unit tests using the bundle loader setting is the best way of running unit tests because it doesn't require you to add your application code to your test target, its not currently supported with iPhone applications (although it does work when developing static libraries, including CocoaToucn static libraries).

The solution is to make sure any classes you are trying to test are added to both your application and unit testing target.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.