iPhony Development – Unit Testing?


I’ve been at it all weekend. Off and on, spawning threads, updating a dumb UI, now exploring Test Driven Design with Cocoa. Here’s an interesting tidbit that I turned up somewhere in the Apple docs last night. (It was past 12am when I read it, I was tired and now I can no longer find it so I might as well be lying to you but…) “Creating unit test targets is not supported for iPhone development…” or so the text read. Why is it that the mobile community thinks they’re so special? Why do they not need unit tests for their software? Am I missing something? I found an article demonstrating how to Test Drive a TicTacToe game in Cocoa and so far it’s been working pretty well. I’m still hitting my random stumbling blocks here and there. My latest blocker comes from the following test auxillary method:

- (void) assertWinnerIs: (int) expectedWinner withMoveInRow: (int) row andInColumn: (int) col {
	int actualWinner = [game makeAMoveInRow: row andInColumn: col];
	NSString *winner = ( (actualWinner == _X_) ? @"_X_" : (actualWinner == _O_ ? @"_O_" : "NONE") );
	STAssertEquals(expectedWinner, actualWinner,
				   @"Move made in row %d and column %d by player %@ should win but returned winner was %@", row, col, 
				   [game valueInRow:row andInColumn:col] == _X_ ? @"_X_" : @"_O_"winner);
	[winner release];
}

It’s complaining about a pointer type mismatch in my conditional expression. I think I’m being too clever here using ternary operators instead of breaking out the classic if/esle or switch statements. I’m just trying to print out exactly which player is reported as the winner in my test because I like fully descriptive assertion failure messages but at the same time I like more terse code. I hate breaking out verbose if/else blocks if I can avoid it.

On a side note, none of this will do me any good if I can’t run test suites in an iPhone project. Still I’m thinking that I could probably hack around the limitation somehow by creating a Cocoa library project just to get the core logic unit tested then somehow figuring out how to include that unit tested code in my iPhone project. I’m certain there’s a loophole somewhere and I’ll stumble across it shortly. I still wonder why it has to be such a challenge? C’mon, we’re in like, the 27th century or something like that! There’s no excuse for any moder frameworks to be created sans unit test support. I view this as completely unacceptable!

3 thoughts on “iPhony Development – Unit Testing?

  1. The thing about unit testing is that its mostly needed by people who

    a) don’t pay attention to the compiler error message
    b) use “NONE” when they mean @”NONE”

  2. I’ll resist the urge to go too deep on this one. Instead I’ll highlight that the REAL DEAL behind unit testing is that its mostly misunderstood by people who want the freedom to ignore compiler error messages and use “NONE” instead of @”NONE”. When used correctly the last thing you think about is the compiler while the self documentation and readability of your code become more apparent.

Leave a Reply

Fill in your details below or click an icon to log in:

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 )

Google+ photo

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

Connecting to %s