[TFUI] Blog posts: Unit testing Cocoa user interfaces

Chris Hanson <[email protected]> Sat, 7 Jul 2007 23:15:32 -0700
Newsgroups gmane.comp.programming.test-first-user-interfaces,gmane.comp.programming.extreme-programming,gmane.comp.programming.test-driven-development
Message-ID <[email protected]>
I've written a couple of posts on my weblog describing how to do unit=20=20
testing =97 and test-driven development =97 of user interfaces using the =
=20
Cocoa application framework that's part of Mac OS X, and the OCUnit=20=20
unit testing framework that's included with the Xcode IDE that's also=20=20
included with Mac OS X.  I thought that at least some members of the=20=20
TDD, XP, and test-first UI communities would find them interesting.

     Unit testing Cocoa user interfaces: Target-Action
     http://chanson.livejournal.com/148204.html

     Unit testing Cocoa user interfaces: Cocoa Bindings
     http://chanson.livejournal.com/172390.html

(In the interest of full disclosure, I work on Xcode at Apple - though=20=20
I've been a member of all three of these communities for several times=20=20
as long as I've worked on Xcode or even at Apple, and I'm not here to=20=20
evangelize.  I don't speak for my employer; I'm just a tools developer=20=20
who's also really passionate about agile development practices and the=20=20
ways they can be applied to improve quality and predictability.)

Cocoa has some relatively unique qualities as an application framework=20=20
that make it easy to do test-driven development with:  You can follow=20=20
a "trust, but verify" approach to test-driving your user interface,=20=20
where can write tests to specify (and verify) that your views and=20=20
controllers are connected to your model correctly and trust that so=20=20
long as it's the case, the framework will behave correctly.=20=20=20
Furthermore, it's built on the Objective-C language, which supports a=20=20
lot of introspection features which you can leverage to make writing=20=20
your tests easier without violating encapsulation too much in the code=20=20
under test.

The upshot of all this is that you don't need to worry about injecting=20=20
events to ensure that the right thing happens when a button is=20=20
clicked, you don't have to worry about implementing "reveal" methods=20=20
to eyeball your interfaces since you're still doing all of your=20=20
interface design in Interface Builder (which isn't a code generator=20=20
and doesn't have their major drawbacks), or anything cumbersome like=20=20
that.

For anyone doing Mac development, I hope these posts provide a useful=20=20
starting point for writing tests for your user interfaces.  For anyone=20=20
not doing Mac development, I hope these provide a useful perspective=20=20
on your own frameworks and ways that you may be able to approach test-=20
driving your user interface development in the future.  I'm sure=20=20
Cocoa's not the only MVC-oriented framework where these techniques can=20=20
be applied; I'd love to hear from others who are doing similar things=20=20
with other frameworks and languages.

   -- Chris



To unsubscribe, email:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
=20
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/TestFirstUserInterfaces/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/TestFirstUserInterfaces/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:TestFirstUserInterfaces-digest-hHKSG33TihhbjbujkaE4pw@public.gmane.org=20
    mailto:TestFirstUserInterfaces-fullfeatured-hHKSG33TihhbjbujkaE4pw@public.gmane.org

<*> To unsubscribe from this group, send an email to:
    TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
=20