I recently came to Graham Lee’s book Test-Driven iOS Development when looking when searching for an in-depth look on unit testing.
Graham’s Book doesn’t make use of mock objects but using what is coming with every Xcode installation – OCUnit.
The unit testing environment lacks mock object, so as soon as you start to dive into test driven development you have to choose your tools.
I’ve decided to start with John Reid’s OCHamcrest/OCMockito and though I found it sometimes difficult to achieve what I needed, I finally was able to work through the books example without greater problems.
I even found a rather bad coding style on my side. So thinking about testing in the first place makes you more thinking about your design and coding style in the first place too.
If you haven’t done unit testing before I strongly recommend the excellent screen casts John made on http://www.qualitycoding.org.
In short – especially using OCHamcrest/OCMockito made the test code shorter and therefor easier to read.
You will see that the project uses storyboarding and more often property declarations and the automatic synthesize behavior. So I even deleted some of the tests where only setter behavior was tested (e.g. testAnswerHasSomeText in AnswerTest.m).
Here are the other things I changed
When you work through the book you see that Graham developed a dataSource and delegate class and then merged the delegate methods into the dataSource class. The class is called ..DataSource.h/.m which I find isn’t ideal.
So the classes, as we need several provider, are all named following that naming convention (TopicTableDataSource -> TopicTableProvider).
Instead of Graham’s BrowseOverflowObjectConfiguration class I moved the code into the AppDelegate and created a protocol to have access to the StackOverflowManager, the AvatarStore and the initial topics array.
I reduced the number […]
