Skip to content

Instantly share code, notes, and snippets.

@danbev
Created August 26, 2012 13:44
Show Gist options
  • Save danbev/3479518 to your computer and use it in GitHub Desktop.
Save danbev/3479518 to your computer and use it in GitHub Desktop.
Building aerogear-ios with xcodebuild

Using xcodebuild to build AeroGear-iOS

The goal of this gist is to document the steps to build AeroGear-iOS using the command line tool xcodebuild. The reason for this could be that an CI server would require these steps, but it might also be handy for developers to be able to trigger a full build and run tests from the command line without having to start XCode.

Start with a newly cloned aerogear-ios, and change into the aerogear-ios directory (or what if you specified a different name when cloning use that name)

Some of the information in this gist was taken from different resources and this blog was a great help.

List the schemes in the workspace

When trying to list the schemes from the aerogear-ios from the command line I get the following (this is using a newly cloned gitrepo):

$ xcodebuild -workspace AeroGear-iOS.xcworkspace -list
There are no schemes in workspace "AeroGear-iOS".

Checking the shared checkbox in the Manage Schemes dialog moves the schemes to AeroGear-iOS.xcodeproj/xcshareddata/xcschemes.

After this is done you can get the list of schemes:

$ xcodebuild -workspace AeroGear-iOS.xcworkspace -list
Information about workspace "AeroGear-iOS":
    Schemes:
        AeroGear-iOS
        Pods
        Pods-AeroGear-iOSTests

You can pull these changed from the following branch

Building AeroGear-iOS scheme

$ xcodebuild -workspace AeroGear-iOS.xcworkspace -scheme AeroGear-iOS clean build

Running the test

Currently there is no scheme for AeroGear-iOSTests so we need to add one.
Start XCode:

$ open AeroGear-iOS.xcworkspace

Perform the following steps to add the new Scheme:

  1. Open the the Edit Scheme menu (CMD+<) and then click on Manage Schemes....
  2. Create a new scheme by using the + button and the set the target of the scheme to be created to AeroGear-iOSTests and set the name to AeroGear-iOSTests as well.
  3. Make the scheme shared like we did for the other schemes as mentioned previously in this gist.
  4. One more setting is required, we need to specify that the Scheme AeroGear-iOSTests is runnable

You can pull these changes from the following branch.

Now, list the schemes from the command line just to verify that they are all there now:

$ xcodebuild -workspace AeroGear-iOS.xcworkspace -list
Information about workspace "AeroGear-iOS":
    Schemes:
        AeroGear-iOS
        Pods
        Pods-AeroGear-iOSTests
        AeroGear-iOSTests

You should now be able to do a run the test from the command line using the build target like so:

$ xcodebuild -workspace AeroGear-iOS.xcworkspace -scheme AeroGear-iOSTests -sdk iphonesimulator TEST_AFTER_BUILD=YES -configuration Debug clean build

You don't have to use the clean target if you have already built, just leave out the clean taget, but this might be what a CI server would choose do to.

When you run this you'll see quite a lot of information scroll by in the console, of which most are environment variables setting that are logged. These can be disabled by unchecking "Show environment variables in build log" as show in this branch.

If you scroll up you'll be able to see that the tests are being run:

Run test suite /Users/danbev/work/jboss/aerogear/aerogear-ios/AeroGear-iOS/Build/Products/Debug-iphonesimulator/AeroGear-iOSTests.octest(Tests)
Test Suite '/Users/danbev/work/jboss/aerogear/aerogear-ios/AeroGear-iOS/Build/Products/Debug-iphonesimulator/AeroGear-iOSTests.octest(Tests)' started at 2012-08-26 14:01:30 +0000
Run test suite AGPipelineSpec
Test Suite 'AGPipelineSpec' started at 2012-08-26 14:01:30 +0000
Run test case AGPipeline_WhenNewlyCreated_ShouldNotBeNil
Test Case '-[AGPipelineSpec AGPipeline_WhenNewlyCreated_ShouldNotBeNil]' started.
2012-08-26 16:01:30.599 otest[35749:707] + 'AGPipeline, when newly created, should not be nil' [PASSED]
Test Case '-[AGPipelineSpec AGPipeline_WhenNewlyCreated_ShouldNotBeNil]' passed (0.019 seconds).

Run test case AGPipeline_WhenNewlyCreated_ShouldHaveAPipe
Test Case '-[AGPipelineSpec AGPipeline_WhenNewlyCreated_ShouldHaveAPipe]' started.
2012-08-26 16:01:30.601 otest[35749:707] + 'AGPipeline, when newly created, should have a pipe' [PASSED]
Test Case '-[AGPipelineSpec AGPipeline_WhenNewlyCreated_ShouldHaveAPipe]' passed (0.001 seconds).

Test Suite 'AGPipelineSpec' finished at 2012-08-26 14:01:30 +0000.
Executed 2 tests, with 0 failures (0 unexpected) in 0.021 (0.021) seconds

Run test suite AGRestAdapterSpec
Test Suite 'AGRestAdapterSpec' started at 2012-08-26 14:01:30 +0000
Run test case AGRestAdapter_WhenNewlyCreated_ShouldNotBeNil
Test Case '-[AGRestAdapterSpec AGRestAdapter_WhenNewlyCreated_ShouldNotBeNil]' started.
2012-08-26 16:01:30.603 otest[35749:707] + 'AGRestAdapter, when newly created, should not be nil' [PASSED]
Test Case '-[AGRestAdapterSpec AGRestAdapter_WhenNewlyCreated_ShouldNotBeNil]' passed (0.001 seconds).

Test Suite 'AGRestAdapterSpec' finished at 2012-08-26 14:01:30 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.002) seconds
...

But why are we using the build target instead of the test target?
Well, lets see what happens if we do:

$ xcodebuild -workspace AeroGear-iOS.xcworkspace -scheme AeroGear-iOSTests -sdk iphonesimulator TEST_AFTER_BUILD=YES -configuration Debug test
Build settings from command line:
    SDKROOT = iphonesimulator5.1
    TEST_AFTER_BUILD = YES

xcodebuild: error: Failed to build workspace AeroGear-iOS with scheme AeroGear-iOSTests.
	Reason: The run destination My Mac 64-bit is not valid for Testing the scheme 'AeroGear-iOSTests'.

According to this blog this is currently not supported and the source of this was Apples Developer support forum, but I've not been able to verify that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment