In a new post to his site Justin Carmony shares some of his experiences with doing test-driven development (TDD) for a new project he was working on interfacing with the Omniture API. In it he shares six lessons he learned during the work.
At work we use Omniture for our web analytics, and for a long time I've wanted query our Omniture Data to run some internal reports. I discovered that Omniture has a restful reporting api, and after using it for a little bit I decided it would be nice to write a wrapper library for it. Since I had recently taken the PHP Testing Bootcamp from Chris Hartjes, I decided I wanted write it using Test Driven Development and really get my feet wet. I also decided I wanted to make the library compatible with Composer. After the weekend was over, I had an almost finished library that just requires some more work to be done, but I learned a great deal that I thought I'd share.
He's broken the post up into sections, each with their own summary:
- TDD is 90% changing the way to write code, and 10% writing tests
- Understanding Mock Objects is the real key.
- It takes almost twice as long to write code and tests then just code
- Its extremely easy to get out of the habit of writing tests.
- You'll refactor quicker and more often when writing tests
- Having testable code made me feel much better about sharing the code.