Unit Testing with SenTestingKit with framework dependencies
December 01, 2010

This is a bit of a technical one… you have been warned…

I’ve got some internal Objective-C frameworks, and they have some unit tests.

I’ve have targets set up for both SenTestingKit and GHUnit, because I like to have the choice of which one to run (I use SenTestingKit from continuous integration scripts, and GHUnit when I want to run the tests manually).

I recently came across a problem when I wanted to test one of my frameworks which uses another one of my frameworks, using SenTestingKit.

The problem is that SenTestingKit builds your tests into a bundle, then runs another application to load that bundle and execute it. This means that, by default, the application that is running your tests doesn’t know where to find any frameworks that your tests depend on.

There are probably a few ways of solving this, but the one I came up with was this:

First, add a copy files phase to your target, and make it copy any dependent frameworks into Contents/Frameworks/ inside the octest bundle that you’re making.

This gives you a known location containing a copy of any frameworks that you’ll need, but it doesn’t automatically tell the unit test running application to look there.

Second, edit the run script which actually invokes the unit test running app.

By default this script looks like this:

    # Run the unit tests in this test bundle.

The trick is to add our plugin’s Frameworks folder to the search path for frameworks, before running the tool:

    # Add the unit test plugin's Frameworks/ path to the search paths for dynamic libraries

    # Run the unit tests in this test bundle.

Bingo - the unit test app now finds the dependent frameworks and runs the tests ok.