One of the biggest gripes that folks have about the built in unit testing for Xcode is that it's a pain to setup and debug. I've also hear from folks that this is the reason they don't write tests, which is a shame. But I'm going to share a little secret with you today: thanks to Objective-C, it's pretty darn easy to roll your own solution.

Here's some code for you: CallTestMethods.m.

I've got that in Acorn's App delegate, stuffed inside a category, and hooked up to a debug menu (named "Sanity") which will run through various tests. All I do then is have methods in my category that start with "test", run the various operations, and then fail with a big fat NSException if something goes wrong. (Bonus points go to the developer who uses the __FUNCTION__ and __LINE__ macros to narrow where the exception is being throw).

And if I want to debug the tests using gdb, there's no targets to change or any fancy environment variables to set. I just launch Acorn with gdb, and run my tests. I've even got it hooked up to my build process these days; I launch Acorn from my build script with a -runtests argument, and away it goes. I'm not sure how much easier it could be. It's very low friction and easy to debug, which is important to me.

It's also not hard to imagine writing your own macros to do the checking, and look! NSAssert is already there!

So consider writing your own if Xcode's SenTest framework isn't working out for you.