Marc Schwieterman

That depends...

Testing in the OSX Sandbox

If you’re running Application Unit Tests, and have just enabled entitlements, you will immediately be greeted with an error similar to the following.

2012-11-26 20:16:56.352 SandboxFail[25356:303] Error loading /Users/marc/Library/Developer/Xcode/DerivedData/SandboxFail-arfkzlcptzkjqjcqelqwsfsxhasn/Build/Products/Debug/SandboxFailTests.octest/Contents/MacOS/SandboxFailTests:  dlopen(/Users/marc/Library/Developer/Xcode/DerivedData/SandboxFail-arfkzlcptzkjqjcqelqwsfsxhasn/Build/Products/Debug/SandboxFailTests.octest/Contents/MacOS/SandboxFailTests, 262): no suitable image found.  Did find:
    /Users/marc/Library/Developer/Xcode/DerivedData/SandboxFail-arfkzlcptzkjqjcqelqwsfsxhasn/Build/Products/Debug/SandboxFailTests.octest/Contents/MacOS/SandboxFailTests: open() failed with errno=1
IDEBundleInjection.c: Error loading bundle '/Users/marc/Library/Developer/Xcode/DerivedData/SandboxFail-arfkzlcptzkjqjcqelqwsfsxhasn/Build/Products/Debug/SandboxFailTests.octest'

It appears that test bundles cannot be injected into a signed application. After a couple failed attempts to sign the test bundle itself, I found a Stackoverflow post that recommended disabling code signing in a separate build configuration. It was not immediately obvious to me how to do that, so here’s what worked for me.

Create Build Configuration

The first thing to do is duplicate the Debug configuration to make one specifically for testing. This is done under the main project configuration, as shown below. I named my new configuration Test.

Duplicate Debug Configuration

Disable Code Signing

Code signing can be disabled in the build settings for the main target of the project. Make sure to expand the disclosure triangle and only clear the settings for the Test configuration. You don’t have to select or type anything specific in the values column. You can just click on Test and hit your keyboard’s equivalent of delete, which will restore the default values.

Disable Code Signing

Configure Schemes

After that you need to open the scheme editor (Command-Shift-<) and select the newly created Test configuration.

Update Test Scheme

Update Dependencies and Clean

If you use Cocoapods to manage your dependencies, you’ll want to run pod install to link the pod lib into the new Test configuration. After that just do a full clean (Command-Option-Shift-K), and you’re ready to run your tests. (Command-U)