views:

230

answers:

2

I've been developing a Mac OS X framework and I want to use OCUnit in my XCode 3.2.1 project. I've followed several tutorials on how to configure a OCUnit test bundle. The problem is that when I create a test case that uses a function that is defined in one of the framework's sources, I get a building error telling me that the symbol is not found.

I made the test bundle dependent of my project's target as the tutorial said, but that doesn't seem to be problem. First I thought that I could solve this problem by dragging the framework's source files into the compile sources section within the Test bundle target, but then all the symbols referenced from that source file started to show up in the build errors, so that seems to not be a good solution/idea.

How can I configure my unit test bundle so it builds properly?

+4  A: 

I also write unit tests against a framework, hopefully I can help. You don't want to recompile framework sources for unit testing — instead, you want to link against the built framework. Here's what I suggest:

  1. Open the info window for the unit testing target by double-clicking on the target in the sidebar.
  2. In the "General" tab, click the + sign in the lower left to add a linked library. Select the framework which your project generates and click "Add". Close the info window.
  3. In each of your unit tests, import the header file(s) that you need for that test. Since Xcode knows about the framework files, you should be able to use the #import "MyHeader.h" form, rather than angle brackets (< and >).

At this point, your unit tests should build without error. If not, perhaps examining how my unit tests are configured for CHDataStructures can help.

Quinn Taylor
+1  A: 

I could make it work by clicking on the checkbox corresponding to my framework(the one that appears in the product section) in the file viewer table that appears in the main windows of Xcode (I guess it put the file as a target o something like that). It seems that dragging the framework to the Unit Test bundle does a different thing.

@Quinn Taylor Thanks for the answer

GuidoMB
When you have the Unit Test bundle selected and click the checkbox for the framework you're building, that includes it in the linking phase. This accomplishes the same thing as adding a linked library, though going through the info pane for the target is usually easier to understand for most people — it's explicit, rather than dependent on the currently active target.
Quinn Taylor