Search code examples
objective-ccocoaunit-testingxcodeocunit

How to configure a OCUnit test bundle for a framework?


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?


Solution

  • 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.