views:

36

answers:

1

In Xcode, when source and test classes in are different folders - In the 'Test' task - how do you link against the source, as opposed to adding the all source files to the test task ?

+1  A: 

The code under test has to be compiled and linked into either an executable or a library or framework. In the later case, just link your unit test bundle against the framework or library (whichever you are producing). In the case of an executbale, you can use bundle injection to inject your unit test bundle into the application at launch and run your unit tests. A tutorial for both scenarios is provided in the Xcode unit testing guide and a briefer overview here.

In short, for an application, set the test target's 'Test Host' property and 'Bundle Loader' property to '$(CONFIGURATION_BUILD_DIR)/MyApp.app/Contents/MacOS/MyApp'.

Barry Wark
Thanks a lot. I found the answer in the link you specified - http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/UnitTesting/1-Articles/CreatingTests.html#//apple_ref/doc/uid/TP40002171-125425 - in the 'Making Your Target Dependent on the Main Executable' section. It was a matter of setting the 'Test' Target's 'Test Host' property and 'Bundle Loader' property to '$(CONFIGURATION_BUILD_DIR)/MyApp.app/Contents/MacOS/MyApp'
Akshay