Just came back from a great class taught by Adam Milligan of Pivotal Labs on Cedar.
Download Cedar here: http://www.github.com/pivotal/cedar
The Readme should be able to lead you through the setup fine, but I wanted to add my notes.
– You’re essentially compiling Cedar, then taking the framework and associating it with your iPhone project.
– You’ll create another target, that will be where you create tests.
– Cedar has a nice iPhone simulator app that displays all of the tests organized by tableview. So you can basically use it to scroll around and see errors.
We did a simple validation in class, checking out a UILabel for content:
#define HC_SHORTHAND
#import
//#import
#import "HelloWorldViewController.h"
SPEC_BEGIN(Spec1)
/* defines the test class */
describe(@"HelloWorldViewController", ^{
__block HelloWorldViewController *controller;
/* want to be available everywhere*/
/* need a block, or else beforeeach wouldn't work */
beforeEach(^{
controller = [[HelloWorldViewController alloc] init];
controller.view; // have to access to prevent lazy loading & not hitting it
});
afterEach(^{
[controller release];
});
it(@"Display a label", ^{
// fail(@"this is a failure");
assertThat(controller.label, notNilValue());
});
/* it(@"should rotate image", PENDING);
it(@"Should fail", ^{
fail(@"this is a failure");
});*/
});
SPEC_END
I can’t tell you how excited I am to start setting up tests on some existing apps. If you’ve ever been in an environment where the tests were created, and developers tested them before releases, you know how great it is to have a good testing framework. I feel a little too “wild west” with solo iPhone app development.
Cedar also comes with a rake task command-line, so you can trigger it from various integration scenarios. Initially I’m going to point some tests as some of my gnarlier algorithms in Bingo, and check for various UI elements.