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

13 Likes

  • Tim Haines 9 months ago
    I am so coming back to watch this when my brain's working again.
  •  
  • Keith Fitzgerald plus 9 months ago
    thank you thank you thank you. great video. learning more about ocunit now. :-)
  •  
  • ThreeE 6 months 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 5 months 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.
  •  
  • ThreeE 5 months 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

1 Related collections

Albums Albums

Statistics

  •  
    plays
    likes
    comments
  • Total
    plays 946
    likes 13
    comments 5
  • Nov 9th
    plays 0
    likes 0
    comments 0
  • Nov 8th
    plays 0
    likes 0
    comments 0
  • Nov 7th
    plays 0
    likes 0
    comments 0
  • Nov 6th
    plays 0
    likes 0
    comments 0
  • Nov 5th
    plays 1
    likes 0
    comments 0
  • Nov 4th
    plays 0
    likes 0
    comments 0
  • Nov 3rd
    plays 0
    likes 0
    comments 0
  • Nov 2nd
    plays 3
    likes 0
    comments 0
Previous Week

Downloads

Please join Vimeo or log in to download the original file. It only takes a few seconds.