Skip to content
idoru edited this page Oct 4, 2012 · 9 revisions

Installation

First, follow the Installation instructions if you haven't already done so before.

Creating test targets

There are different targets for running tests against OS X and iOS. Create the target(s) that make the most sense for your project.

Non-iOS (OS X) testing

  • 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
  • You target is now set up and should include an ExampleSpec.mm.

iOS testing

  • 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.

Running specs

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 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.

Write specs, rinse, repeat

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

Code snippets are installed as part of Cedar. These are installed into ~/Library/Developer/XCode/UserData/CodeSnippets.

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

Command line automation

The Rakefile from the Cedar project contains useful rake tasks that let you run cedar specs from the command line. The ocunit:logic and ocunit:application tasks demonstrate how you can run OCUnit style test bundles. The specs and uispecs tasks show how you can run cedar test suites.

Focused specs

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.

Other useful pages

Clone this wiki locally