00:00
804
Why and how to do unit testing for Cocoa (Mac) applications using OCUnit, which comes with Xcode.

I'm not an iPhone developer, so please don't ask me about testing for iPhone applications. Instead, see this blog post by my friend Colin Barrett: iamthewalr.us/blog/2008/11/10/ocmock-and-the-iphone/

This video is based on a presentation I gave at the December 2008 meeting of CocoaHeads in Lake Forest, California. This version is corrected and expanded from the original.

Credits

Likes

See all likes
  • Tim Haines 3 years ago
    I am so coming back to watch this when my brain's working again.
  •  
  • Keith Fitzgerald plus 2 years ago
    thank you thank you thank you. great video. learning more about ocunit now. :-)
  •  
  • Erik Evenson 2 years ago
    Great stuff.

    My question about testing in Cocoa is how to test singletons. For example, how would I test that a main menu item successfully calls an action on a custom controller? I can't mock up the main menu because it is effectively part of the NSApp singleton -- which I can't use in my test cases...

    Thanks again -- and I love Adium too!
  • Peter Hosey 2 years ago
    I assume you mean “test that choosing a menu item would send an action message to my custom controller”. Restating the question that way makes the answer a bit more obvious: inspect its target and action. Target may be nil; this means “first responder”. Action certainly should not be NULL.

    You can load the main menu nib explicitly. Pass your own object as File's Owner—you may get a warning because it's not an NSApplication, but as long as it has all the necessary outlets (e.g., mainMenu), it should just work.
  •  
  • Erik Evenson 2 years ago
    Thanks Peter -- that's exactly what I'm doing now. I guess I worried too much about that compiler warning.

    I have noticed that (I think) OCUnit runs your tests in parallel. This has made testing a little more tricky for me. Some of my code wasn't designed to run in parallel -- although now it is because of OCUnit. Added bonus I guess!
  •  
This conversation is missing your voice. Take five seconds to join Vimeo or log in.

Advertisement

About this video

FLV
00:13:24
  • 1280x720, 15.65MB
  • Uploaded Mon January 05, 2009
  • Please join or log in to download

Statistics

Date Plays Comments
Totals 2,282 18 5
Feb 14th 0 0 0
Feb 13th 1 0 0
Feb 12th 1 0 0
Feb 11th 1 0 0
Feb 10th 0 0 0
Feb 9th 0 0 0
Feb 8th 2 0 0