8000 GitHub - ixx1232/xctool: A replacement for Apple's xcodebuild that makes it easier to build and test iOS or OSX apps.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ixx1232/xctool

 
 

Repository files navigation

xctool

xctool is a replacement for Apple's xcodebuild that makes it easier to build and test iOS and Mac products. It's especially helpful for continuous integration.

Build Status

[ Features • Requirements • Usage • Continuous Integration • Reporters • Configuration • Contributing • Known Issues & Tips • License ]

Features

xctool is drop-in replacement for xcodebuild that adds a few extra features:

  • Structured output of build and test results.

    xctool captures all build events and test results as structured JSON objects. If you're building a continuous integration system, this means you don't have to regex parse xcodebuild output anymore.

    Try one of the Reporters to customize the output or get the full event stream with the -reporter json-stream option.

  • Human-friendly, ANSI-colored output.

    xcodebuild is incredibly verbose, printing the full compile command and output for every source file. By default, xctool is only verbose if something goes wrong, making it much easier to identify where the problems are.

    Example:

    pretty output

  • Faster, parallelized test runs.

    xctool can optionally run all of your test bundles in parallel, speeding up your test runs significantly. At Facebook, we've seen 2x and 3x speed ups by parallelizing our runs.

    Use the -parallelize option with run-tests or test to enable. See Parallelizing Test Runs for more info.

  • Written in Objective-C.

    xctool is written in Objective-C. Mac OS X and iOS developers can easily submit new features and fix any bugs they may encounter without learning a new language. We very much welcome pull requests!

Requirements

  • Xcode 5 or higher
  • You'll need Xcode's Command Line Tools installed. From Xcode, install via Xcode → Preferences → Downloads.

Installation

xctool can be installed from homebrew via

brew install xctool

or can be downloaded and run via the xctool.sh command.

Usage

xctool's commands and options are mostly a superset of xcodebuild's. In most cases, you can just swap xcodebuild with xctool and things will run as expected but with more attractive output.

You can always get help and a full list of options with:

path/to/xctool.sh -help

Building

Building products with xctool is the same as building them with xcodebuild.

If you use workspaces and schemes:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  build

If you use projects and schemes:

path/to/xctool.sh \
  -project YourProject.xcodeproj \
  -scheme YourScheme \
  build

All of the common options like -configuration, -sdk, -arch work just as they do with xcodebuild.

NOTE: xctool doesn't support directly building targets using -target; you must use schemes.

Testing

xctool has a test action which knows how to build and run the tests in your scheme. You can optionally limit what tests are run or change the SDK they're run against.

To build and run all tests in your scheme, you would use:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  test

To build and run just the tests in a specific target, use the -only option:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  test -only SomeTestTarget

You can go further and just run a specific test class:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  test -only SomeTestTarget:SomeTestClass

Or, even further and run just a single test method:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  test -only SomeTestTarget:SomeTestClass/testSomeMethod

You can also run tests against a different SDK:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  test -test-sdk iphonesimulator5.1

Building Tests

While test will build and run your tests, sometimes you want to build them without running them. For that, use build-tests.

For example:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  build-tests

You can optionally just build a single test target with the -only option:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  build-tests -only SomeTestTarget

Running Tests

If you've already built tests with build-tests, you can use run-tests to run them. This is helpful if you want to build tests once but run them against multiple SDKs.

To run all tests, you would use:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  run-tests

Just as with the test action, you can limit which tests are run with the -only. And, you can change which SDK they're run against with the -test-sdk.

By default application tests will wait at most 30 seconds for the simulator to launch. If you need to change this timeout, use the -launch-timeout option.

Parallelizing Test Runs

xctool can optionally run unit tests in parallel, making better use of otherwise idle CPU cores. At Facebook, we've seen 2x and 3x gains by parallelizing our test runs.

To allow test bundles to run concurrently, use the -parallelize option:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  run-tests -parallelize

The above gives you parallelism, but you're bounded by your slowest test bundle. For example, if you had two test bundles ('A' and 'B'), but 'B' took 10 times as long to run because it contained 10 times as many tests, then the above parallelism won't help much.

You can get further gains by breaking your test execution into buckets using the -logicTestBucketSize option:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  run-tests -parallelize -logicTestBucketSize 20

The above will break your test execution into buckets of 20 test cases each, and those bundles will be run concurrently. If some of your test bundles are much larger than others, this will help even things out and speed up the overall test run.

Continuous Integration

xctool is an excellent choice for running your tests under a continuous integration server such as Travis CI or Jenkins. In order to your run your tests within a continuous integration environment, you must create Shared Schemes for your application target and ensure that all dependencies (such as CocoaPods) are added explicitly to the Scheme. To do so:

  1. Open up the Manage Schemes sheet by selecting the Product menu > Schemes > Manage Schemes...
  2. Locate your application target in the list. Ensure that the Shared checkbox in far right hand column of the sheet is checked.
  3. If your application or test targets include cross-project dependencies such as CocoaPods, then you will need to ensure that they have been configured as explicit dependencies. To do so:
    1. Highlight your application target and hit the Edit... button to open the Scheme editing sheet.
    2. Click the Build tab in the left-hand panel of the Scheme editor.
    3. Click the + button and add each dependency to the project. CocoaPods will appear as a static library named Pods.
    4. Drag the dependency above your application target so that it is built first.

You will now have a new file in the xcshareddata/xcschemes directory underneath your Xcode project. This is the shared Scheme that you just configured. Check this file into your repository and xctool will be able to find and execute your tests on the next CI build.

Example Travis CI Configuration