xcodeoctest

What conditions enable the Xcode 4 "Product > Test" menu option?


It's not entirely clear what enables the "Test" option for a product in Xcode 4. It is enabled when you create a new project with an associated .octest target.

Is there a flag or an option to link a particular target as a test of another? The reference material only seems to talk about making tests when they are working, not getting them working in the first place.

What I'm trying to do is use a non-Objective-C test framework, in this case Catch, for testing a cross-platform C++ application. Objective-C, with the associated Foundation library, is not available on the target.


Solution

  • If you need to add third-party test frameworks to an Xcode project, you can do this by replacing the "Build Phase" associated with running what is, by default, otest.

    Add a target that compiles your third-party test suite into an executable form. This is independent to the .octest target.

    Add this target as a dependency of the main ".octest" target under "Build Phases", "Target Dependencies" to ensure the tests are compiled as required.

    Replace the "Run Script" section with whatever is required to execute your tests. Typically it looks something like:

    DYLD_LIBRARY_PATH=$TARGET_BUILD_DIR "${TARGET_BUILD_DIR}/myCustomTests"
    

    This presumes there's an executable called myCustomTests produced by the custom test target and also configures the DYLD_LIBRARY_PATH to include the build directory so that any custom libraries are loaded properly.