Unit Testing Framework & GUI for Mac OS X and iPhone (GHUnit)

February 21, 2009 — 10 Comments

I’ve always wondered why XCode doesn’t have a unit testing GUI like other IDEs, or why the SenTesting framework has to be such a pain to setup, with all its RunScript build phases, shell scripts, octest bundle insanity. After using the GTMTestCase for the iPhone (since SenTesting isn’t supported on the iPhone SDK) I decided to try to re-purpose some of the GTM Unit Testing code into a standalone testing framework and GUI that I could use on both my Mac OS X and iPhone projects.

GHUnit (pronounced ˈgü-ˈnit, I guess?), hosted at gabriel/gh-unit, is meant to be installed as a framework, and run as an application in a separate Test target. The idea being that you can run and crash into the XCode debugger directly and utilize all the debugging techniques that you normally use. The test GUI should allow you to see test failures more clearly, view timings / stats and not have to go fishing for the build console window. And an automated way to view stack traces.

Details on how to use the framework are included in the README.

GHUnit Test GUI for Mac OS X App

GHUnit Test GUI for Mac OS X App

Unit Test GUI for iPhone App

Unit Test GUI for iPhone App

For the iPhone side, I included a similar GUI that runs the tests in the simulator.

GHUnit can be used as a standalone test framework (by subclassing GHTestCase), or with your existing SenTestCase tests or GTMTestCase tests.

So far its pretty basic, but I am using it on a couple projects and its been helping my development a bunch and letting me to write tests as I go without completely destroying my workflow or sanity.

Any feedback is appreciated and let me know if you have any problems with the install/embed instructions or in general. Also thanks to the GTM peeps, on which much of this is based.

Maybe the next step is an XCode plugin?

10 responses to Unit Testing Framework & GUI for Mac OS X and iPhone (GHUnit)

  1. Looks very nice. From the nice standalone test output UI can we/could we rerun individual tests?

  2. I’ve been thinking about whether its possible to use the Fix & Continue, to edit a test and re-run without having to quit and re-compile? (Am dreaming about some crazy autotest mode.) But I think initially, a quick way to run or re-run a single test case or method would totally be useful.

    BTW, started a google group @ http://groups.google.com/group/ghunit

  3. Just noticed the GHUnit.framework headers were missing from the 0.2.6 build. Fixed in 0.2.7.

  4. Thanks for the framework!

    I wrote a review of three iPhone unit testing frameworks: OCUnit, GTM iPhone Unit Test, and GHUnit. Out of all of them I liked GHUnit the most! There are a few GUI issues, but that’s something that can be fixed. Details at the bottom of the post: http://paulsolt.com/2010/11/iphone-unit-testing-explained-part-1/

    I’m writing a series of posts on iPhone unit testing and will be continuing to feature GHUnit.

  5. Ernie Biancarelli January 16, 2011 at 8:48 am

    Thanks for this framework. I spent hours trying to get unit testing within Xcode working to no avail. With this framework, it took about an hour to figure out what to do and then I was off and running. Thank!

  6. Hello Gabe, Any updates on segment fault in 10.6?? It would be great if you provide a fix for it.

  7. I heard reports of it not segfaulting in Lion…. But otherwise I am still baffled..

Trackbacks and Pingbacks:

  1. Michael Tsai - Blog - GHUnit - February 23, 2009

    [...] is a new unit testing framework for Mac OS X from Gabriel Handford: I’ve always wondered why XCode doesn’t have a unit testing GUI like other IDEs, or why [...]

  2. This is Tyler Fitch » Blog Archive » links for 2009-03-12 - March 13, 2009

    [...] rel=me » Blog Archive » Unit Testing Framework & GUI for Mac OS X and iPhone (GHUnit) (tags: programming osx iPhone testing unit xcode) Posted in del.icio.us | [...]

  3. Unittest Your Cocoa Application with GHUnit - March 21, 2010

    [...] requirements. So I searched for some frameworks to make tests for my Cocoa application. I found GHUnit. A preoject started by Gabriel Handford. The source is available on [...]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s