Friday, June 14, 2013

Learning TDD

So starting to learn TDD has been on my mind for some time. I've had a few people ask me to use it during my tutorials and I've never really "had time". It would be more appropriate to say that I didn't want to start using it in my daily coding since I don't have to use it during my day job. In other words, it didn't interest me enough to begin using it.

So this week I decided to pick up a book on writing Unit Tests and started a course on TDD. As the instructor of the course said, Writing good tests and doing TDD are 2 completely separate skills. You can follow TDD and still write bad tests. You can also write good tests, but not have a failing test drive your development.

After getting started I realized something yesterday. I started my Intro To Photon videos and blogs. When I became frustrated with the code, I started over again from "scratch" having gained an understanding of how things could be set up. It also allowed me to look at the Server2Server code in the newly released Photon 3.0. When I became frustrated with that code set, I started over yet again and created the Photon Framework. Each of these was better than the previous version and I wanted to look into TDD, but got myself wrapped around the axle for how to "test" code that wasn't mine.

In the end, I decided that my tutorial videos will continue to use the current Photon Framework, but in the background I have started over from scratch yet another time. This time, however, I started with TDD. I started with nothing more than the notion of a server that could add and remove clients from a list. Since yesterday, I have created a suite of 32 tests that cover 12 functions which are helping me keep to my "design specifications" that I have built over the last 3 iterations of the same set of code.

The more I play with TDD, the more I like how it sets me up to accomplish what I want to do and still gives me the ability to refactor it and ensure that the same basic rules still apply.

No comments: