-
Notifications
You must be signed in to change notification settings - Fork 140
Standalone Setup
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:
- Your real application is never run under test, which avoids problems where the execution of real application affects the outcome of the tests.
- 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.
-
For iOS:
- Start by creating a new target of type
Single View Application
to host your tests, we'll call this your Spec App. - Add cedar as a dependency to this application, similar to how it is added to a test bundle on the Installation page.
- Remove the
AppDelegate
,ViewController
,Main.storyboard
files. - Edit the target settings for 'Spec App':
- Under 'General', clear the setting for 'Main Interface'
- Rename the
main.m
file in your Spec App tomain.mm
- 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])); } }
- Start by creating a new target of type
-
For OS X:
- Start by creating a new command line tool to host your tests, we'll call this your Spec App.
- Add cedar as a dependency to this application, similar to how it is added to a test bundle on the Installation page.
- Rename the
main.m
file in your Spec App tomain.mm
- Rename the
- 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(); } }
- Add code from your application that you want test to your Spec App.
- Add Cedar specs to your Spec App.
- Select your Spec App target and run it with ⌘ + R to execute your tests.
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:
-
Build your spec app with Xcode's
xcodebuild
command line utility. For example, if your app has a workspace namedMyApp
and a spec app namedSpecs
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. -
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:
-
Build your spec app with Xcode's
xcodebuild
command line utility. For example, if your app has a workspace namedMyApp
and a spec app namedSpecs
, 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 thexcodebuild
man page for more options you can use here. -
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
-