Monday, 28 January 2013

A Return to Unit Testing using xcodebuild

I have previously written a couple of posts on the testing of iOS applications by executing command line only commands. What I did:

xcodebuild -sdk iphonesimulator -project JonsProject.xcodeproj -target JonsProjectTest -configuration Debug TEST_AFTER_BUILD=YES

This used to fire up the simulator and execute the test schema. Now I get this:

/Applications/ warning: Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set).

Partly I think that I might have lost my mind as the tests worked, I saw them work, they worked!  However, the build server on which all of this worked now does not, but then the scripts for the CI

have changed. So, which stopped working first? Who knows, but it's not adding to my positive mental health.

Anyway at least one of my colleagues has been suggesting that we use this run the simulator and execute the tests:

I am not sure that this is a wonderful idea as it appears to involve compiled in binaries. Which I don't think I agree with. You shouldn't have to alter your code to use what is a base "feature" of the IDE.

After a bit of poking around the script that gets executed there are these blocks of code:

RunTestsForApplication() {
    Warning ${LINENO} "Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set)."


if [ "${TEST_HOST}" != "" ]; then
    # All applications are tested the same way, by injecting a bundle.
    # The bundle needs to configure and run the tests itself somehow.

    RunTestsForApplication "${TEST_HOST}" "${TEST_BUNDLE_PATH}"

    # If no TEST_HOST is specified, assume we're running the test bundle.
    RunTestsForBundle "${TEST_BUNDLE_PATH}"

Which kind of implies that RunTestsForApplication will be supported in the future and is somehow related to the setting of the TEST_HOST environment variable.  But what happens if you set that variable to blank?  Well, given this command:

xcodebuild -sdk iphonesimulator -project JonsProject.xcodeproj -target JonsProjectTests -configuration Debug  TEST_AFTER_BUILD=YES TEST_HOST=""

The unit tests run.  And fail, correctly, in my case.

error: -[JonsProjectTests testExample] : Unit tests are not implemented yet in Jons Password KeeperTests
Test Case '-[JonsProjectTests testExample]' failed (0.000 seconds).

Test Suite 'JonsProjectTests' finished at 2013-01-28 10:25:32 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.000) seconds

Test Suite '/build/Debug-iphonesimulator/JonsProjectTests.octest(Tests)' finished at 2013-01-28 10:25:32 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.001) seconds

But, but, but the simulator isn't open.  I remember, distinctly, that to get this lot working in the past, the simulator HAD to be open.

I am so losing my mind.


  1. Try

  2. Try this:

    xcodebuild test -scheme JonsProject -configuration Debug -sdk iphonesimulator7.0 -destination OS=7.0,name="iPhone Retina (4-inch)"

  3. Thanks for this blog. provided great information. All the details are explained clearly with the great explanation. Thanks for this wonderful blog. Step by step processes execution are given clearly.Know the details about different thing.
    Home Automation in Chennai
    smart home in Chennai
    Home security in Chennai
    Burglar alarm in Chennai
    Wifi Camera Chennai

  4. Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Great work admin.Keep update more blog.
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

  5. Hi,

    Thanks for sharing a very interesting article about A Return to Unit Testing using xcodebuild. This is very useful information for online blog review readers. Keep it up such a nice posting like this.

    Maestro Infotech,
    Web Design Company Bangalore

  6. This article gives the light in which we can observe the reality. this is very nice one and gives in-depth information. Thanks for this nice article
    Web design company in chennai
    Web development company in chennai
    Mobile app development company in chennai

  7. Excellent Article. Well, the main reason of me sharing my post here is that, Lets Connect over the Digital Marketing Company in India and we also open for Partnerships with Mobile App Development, Website Development and Graphics related company !

    Get in touch with the Digital Marketing Service Provider In India for more information