I’ve taken on a new client project and with this project I’ve decided it’s time I started learning to use Test Driven Development (TDD) for my iOS projects. There are many benefits to test driven development but for me I think I’m most looking forward to being able to refactor my code so as to improve the quality and robustness without risk of breaking interfaces between the various modules.
Quality Coding
I’ve been following the advice of Jon Reid on Quality Coding. Jon’s articles went into a lot of detail on TDD topics that had always confused me. I learned a lot about letting the tests drive the design of my software and how to know which tests need to be written. I highly recommend reading through the posts on his site.
I also started performing code kata to practice the skills necessary to work through TDD. I think I need more here as I’ve been finding that I spend a lot of time trying to figure out how to use various testing tools to achieve the testing and designs I need. I started with the bowling game kata on http://qualitycoding.org. I’ve also been working through FizzBuzz.
Tools
From Jon’s site I’ve learned to use OCMockito to create mocks and stubs to interact with the classes I’m testing. And, I’ve learned to use OCHamcrest to verify the results I’m looking for. I’ve found these tools easy to work with and quite helpful in developing my tests.
I have started to find a need for features not yet in OCMockito releases. For example, partial mocking. Some of the classes I’ve been developing would benefit from partial mocking techniques and as such I’ve started using OCMock as well. I’m not excited about mixing the two libraries within single tests but in some cases that’s what I’ve had to do.
Speed
I’ve been thinking about the speed at which I’m working with TDD. I feel that at this time I spend a lot of time learning how to use the tools. Sometimes I even feel like I’m fighting against them. Many changes I’ve made have failed tests even though the logic n the code is ultimately correct. But the tests end up failing due to issues with the way I’ve chosen to mock up objects.
I am hoping that as I continue I will gain more experience with mocking and with writing testable code. Also, I think that in TDDing all of my code I’m probably exposing myself to more of these problems than I would otherwise.
Despite the growing pains I’m experiencing with TDD I have been quite productive over the last week. TDD has helped me to keep focused on my tasks. The test driven development has made it easier for me to see and develop the next steps in the project.
Next Steps
I’m going to continue using TDD on this project but I need to work on learning and practicing the relevant skills. My goals for the next two weeks are:
- Practice with the tools (OCMockito, OCHamcrest, OCMock, others).
- Do less up front design and trust the the tests to drive the development.
- Include more classes in the TDD. I’ve been skipping TDD on my View Controllers.
I’m also going to work on resolving some of the issues with my tools. I may focus more on OCMock for new class development as it better meets my needs. But I will also be watching for updates to OCMockito and its partial mocking support.
I’ll write about my progress in another two weeks.