Getting Started with Cedar: iPhone Testing Framework

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 <OCHamcrest-iPhone/OCHamcrest.h>
//#import <OCMock-iPhone/OCMock.h>
#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.

  • George James

    I am using cedar in my ios project and i have a scenario where i am coding like
    [RightNavigationItemView setWithViewController:self title:@"Done" Action:@selector(doneButtonTapped:)];
    RightNavigationItemView is a class where i am customizing the right navigation button using the following code

    + (RightNavigationItemView *)setWithViewController:(UIViewController *)viewController title:(NSString *)title Action:(SEL)selector {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@”RightNavigationItemView” owner:self options:nil];
    RightNavigationItemView *item = [topLevelObjects objectAtIndex:0];
    [item.rightButton setTitle:title forState:UIControlStateNormal];
    [item.rightButton addTarget:viewController action:selector forControlEvents:UIControlEventTouchUpInside];
    item.rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:item.rightButton];
    viewController.navigationItem.rightBarButtonItem = item.rightBarButton;

    return item;
    }
    now how can i write cedar test cases to check the rightNavigationButton title?
    please help me on this

  • Nice post.Its really interesting.I enjoy at the time of reading this post.You have done a good job by sharing this post with us.I really like this.Keep in touch with us.

  • Nice article about light bulbs.I liked the post.Good job.Thanks for sharing such post.

  • I am glad I found this article because i am surfing for something like this .I really enjoy at the time of reading this post.Its fantastic.Keep in touch with us in future too.

  • Nice tutor. Your way of presentation is too good.You have done a good job by sharing this informative post with us.Its really great.Keep in touch with us in future too.

blog comments powered by Disqus