-
Notifications
You must be signed in to change notification settings - Fork 140
Getting started
First, follow the Installation instructions if you haven't already done so before.
There are different targets for running tests against OS X and iOS. Create the target(s) that make the most sense for your project.
- Select your project in Xcode to bring up the project editor.
- Click on "Add Target".
- Select "Cedar" under the Mac section.
- Select either an OSX Cedar Testing Bundle or a OSX Cedar Spec Suite. If you prefer to run a separate target to see your spec results, choose the spec suite. If you prefer to run your specs with Xcode's built-in OCUnit runner, choose the testing bundle. Name this target Specs, or something else suitable.
- If you created a spec bundle, you must additionally add it to the list of tests
for the intended target:
- Select the target you want the tests to run against.
- Edit the scheme (
Cmd-<
) - Select Test and then add your spec bundle to the list of tests
- Your target is now set up and should include an
ExampleSpec.mm
. - For more information on customizing your test installation, see Configuration.
- Select your project in Xcode to bring up the project editor.
- Click on "Add Target".
- Select "Cedar" under the iOS section.
- Select either an iOS Cedar Testing Bundle or a iOS Cedar Spec Suite. If you prefer to run a separate target to see your spec results, choose the spec suite. If you prefer to run your specs with Xcode's built-in OCUnit runner, choose the testing bundle. Name this target Specs, or something else suitable.
- If you're creating a spec bundle, you must specify the intended target of your tests
when creating it in the Test Target field. Additionally, once you have created your
spec bundle target, you must then add it to the list of tests for the test target:
- Select the test target.
- Edit the scheme (
Cmd-<
) - Select Test and then add your spec bundle to the list of tests.
- Your target is now set up and should include an
ExampleSpec.mm
. - For more information on customizing your test installation, see Configuration.
Depending on whether you created a bundle or a suite:
- Spec bundle: Select your app target and then select Test (
Cmd-U
) from the Product menu. - Spec suite: Select your spec suite target and then select Run (
Cmd-R
) from the Product menu.
When your run your specs, you should see output in the console or iOS simulator indicating which specs have passed and which have failed. A newly created target should run all the specs in ExampleSpec.mm
successfully.
At this point, you can add your own specs to your new target. Check out Writing Specs for more details on what is possible. ExampleSpec.mm is purely for demonstration purposes and can be deleted.
Code snippets are installed as part of Cedar. These are installed into
~/Library/Developer/XCode/UserData/CodeSnippets
for Xcode, and ~/Library/Preferences/appCode20/templates
for AppCode.
Here's a list of the completion shortcuts and what they do:
Shortcut | Yields... |
---|---|
cdesc | describe |
ccont | context |
cit | example (it with block) |
cbef | beforeEach |
caft | afterEach |
cshare | sharedExamplesFor |
cbl | itShouldBehaveLike |
cpend | pending example (it with PENDING) |
PENDING | expands PENDING into an empty block |
All of the above constructs are described in Writing Specs
Every Cedar target added to your project contains a Rakefile in its folder which you can use to run your specs from the command line. This is especially useful for running your tests on a Continuous Integration server.
The task in the Rakefile which runs your tests has the same name as the test target you added to your project. You may wish to create a top-level Rakefile in your project's directory which contains project-wide tasks. In this case you can include the Rakefile from your Cedar target(s) to incorporate them into it, as shown below:
Project structure:
YourProject/
├── Rakefile <-- Created by you
├── DomainSpecs/
│ └── Rakefile <-- Created by Cedar
├── UISpecs/
│ └── Rakefile <-- Created by Cedar
└── YourApp
The top-level Rakefile ('YourProject/Rakefile') which you create might look something like this:
load "UISpecs/Rakefile"
load "DomainSpecs/Rakefile"
desc "Run UISpecs and DomainSpecs tasks by default"
task :default => [ :UISpecs, :DomainSpecs ]
#... other tasks e.g. testflight build ...
Sometimes when debugging or developing a new feature it is useful to run only a
subset of your tests. That can be achieved by marking any number of examples
with an 'f'. You can use fit
, fdescribe
and fcontext
like this:
fit(@"should do something eventually", ^{
// ...
});
If your test suite has at least one focused example, all focused examples will run and non-focused examples will be skipped and reported as such (shown as '>' in default reporter output).
It might not be immediately obvious why the test runner always returns a non-zero exit code when a test suite contains at least one focused example. That was done to make CI fail if someone accidently forgets to unfocus focused examples before commiting and pushing.
Note: For improved Xcode integration see CedarShortcuts, an Xcode plugin that provides keyboard shortcuts for focusing on specs under editor cursor.