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.

15 Comments »

  1. Comment by søgemaskineoptimering

    Posted on March 5, 2011 at 4:22 pm

    The party is slowly getting started at Cedar Village. By noon, the temperature had hit 55 degrees and students were milling outside in groups, relaxing, tossing footballs and planning for what is certain to come. Michigan State University senior …

  2. Comment by India Travel Guide

    Posted on March 9, 2011 at 7:27 am

    Cedar brings BDD-style testing to Objective C, now that the … What is a good tutorial for getting started with iPhone unit testing using OCUnit? … How to use Xcode built-in unit testing framework to test C functions? …

  3. Comment by Dating

    Posted on May 29, 2011 at 7:57 am

    A partial commitment doesn't get us going,” Dannen said Wednesday. “You go back
    to the McLeod Center, you had to have 95 percent of that in or committed to it
    before getting started.” Dannen indicated additional “Imagine the Impact”
    funds could be …

  4. Comment by Leather Sofa Furniture

    Posted on June 2, 2011 at 3:55 pm

    Once iPhone SDK 4.0 comes out with support for blocks this should all
    work without the need for the PLBlocks runtime. That won't help iPad
    development for the foreseeable future, though.

  5. Comment by same258

    Posted on June 2, 2011 at 4:40 pm

    A growing number of agencies are testing Apple devices in field
    trials, and some have begun distributing them to workers. What does this
    mean for RIM's BlackBerry, which is widely used by the feds? It's too
    early to say that Apple's gain in government

  6. Comment by Modern Bedroom Sets

    Posted on June 3, 2011 at 3:03 am

    When the Camerons moved into their new four-bedroom apartment

  7. Comment by payday loan payday loan

    Posted on June 3, 2011 at 5:45 pm

    ust came back from a great class taught by Adam Milligan of Pivotal Labs
    on Cedar. Download Cedar here: http://www.github.com/pivotal/… 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.

  8. Comment by Modern Dining Tables

    Posted on January 27, 2012 at 3:26 pm

    We tested Windows 8 on a Samsung Galaxy tablet, on Lenovo notebooks, … Net Framework or Silverlight apps. Today, Metro is available on tablets and …

  9. Comment by Decorating Small Space

    Posted on January 28, 2012 at 6:55 am

    We tested Windows 8 on a Samsung Galaxy tablet, on Lenovo notebooks, … Net Framework or Silverlight apps. Today, Metro is available on tablets and …

  10. Comment by William

    Posted on February 22, 2012 at 2:42 am

    Thanks for this, I really liked it.I’ve recommended this blog to some of my colleagues. I’m sure they’ll find it is useful as I did. Can’t wait to read more.

  11. Comment by Zena

    Posted on March 21, 2012 at 11:48 am

    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.

  12. Comment by tracy

    Posted on April 2, 2012 at 11:51 am

    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.

  13. Comment by Yarout

    Posted on May 18, 2012 at 8:24 am

    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.

  14. Pingback by banane » Blog Archive » Testing? For iPhone? Mooooo….

    Posted on July 10, 2012 at 8:09 pm

    […] wrote a blog post about Cedar way back in the day. Now, Xcode ships with […]

  15. Comment by George James

    Posted on February 20, 2014 at 7:00 am

    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

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>