Skip to content
Sam Coward edited this page Mar 23, 2016 · 7 revisions

Standalone setup runs Cedar without any underlying test framework (SenTestingKit or XCTest). In this scenario, rather than having bundles of tests which are executed against your application, you create a standalone application which runs your tests. This has two main advantages:

  1. Your real application is never run under test, which avoids problems where the execution of real application affects the outcome of the tests.
  2. Cedar reports more clearly when tests are skipped or pending.

Because the tests themselves are a separate application, you also need to add any code you are testing from your application, to the test application as well.

Getting set up

  • For iOS:

    1. Start by creating a new target of type Single View Application to host your tests, we'll call this your Spec App.
    2. Add cedar as a dependency to this application, similar to how it is added to a test bundle on the Installation page.
    3. Remove the AppDelegate, ViewController, Main.storyboard files.
    4. Edit the target settings for 'Spec App':
      1. Under 'General', clear the setting for 'Main Interface'
      2. Rename the main.m file in your Spec App to main.mm
    5. Edit the main.mm file in your Spec App, and change it to the following:
      #import <UIKit/UIKit.h>
      #import <Cedar/Cedar-iOS.h>
      
      int main(int argc, char * argv[]) {
          @autoreleasepool {
              return UIApplicationMain(argc, argv, nil, NSStringFromClass([CedarApplicationDelegate class]));
          }
      }
  • For OS X:

    1. Start by creating a new command line tool to host your tests, we'll call this your Spec App.
    2. Add cedar as a dependency to this application, similar to how it is added to a test bundle on the Installation page.
      1. Rename the main.m file in your Spec App to main.mm
    3. Edit the main.mm file in your Spec App, and change it to the following:
      #import <Cedar/Cedar.h>
      
      int main (int argc, const char *argv[]) {
          @autoreleasepool {
              return CDRRunSpecs();
          }
      }

Adding and running specs

  1. Add code from your application that you want test to your Spec App.
  2. Add Cedar specs to your Spec App.
  3. Select your Spec App target and run it with + R to execute your tests.

Running specs from the command line

Running standalone specs from the command line is useful when you want to run your tests as part of a pre-checkin script, or in a continuous integration environment. You'll have to first build your spec app and then run it.

  • For iOS:

    1. Build your spec app with Xcode's xcodebuild command line utility. For example, if your app has a workspace named MyApp and a spec app named Specs and you would like to run it on the iPhone 6 simulator running iOS 8.1, you'd build it like so:

      xcodebuild -workspace MyApp.workspace -scheme Specs -destination platform='iOS Simulator',OS=8.1,name='iPhone 6' clean build install
      

      By default, this builds your spec app into /tmp/MyApp.dst/Applications/Specs.app. xcodebuild has a vast array of options, see its man page for more details.

    2. Launch your app using ios-sim 3.1.1 or later (or similar tool of your choosing). For example, to launch the app we just built on the iPhone 5s simulator with iOS 8:

      ios-sim launch /tmp/MyApp.dst/Applications/Specs.app --devicetypeid 'com.apple.CoreSimulator.SimDeviceType.iPhone-5s, 8.1'
      
  • For OS X:

    1. Build your spec app with Xcode's xcodebuild command line utility. For example, if your app has a workspace named MyApp and a spec app named Specs, you'd build it like so:

      xcodebuild -workspace MyApp.workspace -scheme Specs clean build install
      

      By default, this builds your spec app into /tmp/MyApp.dst/usr/local/bin/Specs. See the xcodebuild man page for more options you can use here.

    2. Run your app from an OS X shell. To run the spec app in our example, this would be:

      /tmp/MyApp.dst/usr/local/bin/Specs