The Joy of Teaching TDD

Posted on May 01, 2014 - Subscribe - Home

My title is "Lead Developer". I write & review code and help my coworkers improve. I see my coworkers improve and learn everyday. Everyone has their own experience level and TDD exposure. The current code bases don't provide a great TDD experience. Add inexperience and it's no surprise people can't or are not interested in TDD. I was able to turn this around for one coworker and that was better than any other other professional achievement.

I noticed him struggling over the past couple of weeks. He was working on refactoring/reimplementing a large part of the application. He was doing it in the context of a running application with a poor test suite. He was spiking, I use the term loosely, on the new implementation. He had something working but the code was in no way shippable. The scope was so large that he could not explain it to me or anyone else on the team. Something needed to change.

We started to pair and I walked him through the entire process of creating a PR, writing commits, and creating tests. We started off with the simplest tests. They could pass attr_accessor calls. Then slowly and very incrementally building up functionality. Red, Green, Refactor, Commit. He was concerned in the beginning about why we would even do such a thing when the code would be removed. I asked him to trust me and we plowed on. We did an effective exercise where one person writes the test and the other does the implementation. We alternated like this so he could get a feel for the process. I could not pair with him for the entire task. I created an ordered list of tests to write. This would illustrate incremental improvements with the end goal in mind. This was his path into a new adventure.

I talked with him a day or two ago. He told me everything had changed for him--he had that "ah ha! moment"--that one moment of clarity where development makes sense again. Testing was not intimidating anymore. The benefits of small incremental changes driven by tests were apparent over big-bang commits. He said he felt like a brand new developer and that he could never understand how he worked before. I could not be happier for him! This was the change from an unconfident programmer into one who felt like in control again. Most of all he's happier. He knows how to improve his skills and transitively the code itself. This put a huge smile on my face. Maybe it wasn't on my actual face but I was dancing inside. I remembered when I had that zen moment. I wish I could bottle and up and just give to other programmers. It's the best feeling in the world and that wouldn't happened if we didn't sit down and pair together.

There are two things in this world that are useless in isolation: happiness & knowledge. Happiness is nothing unless it's shared. Knowledge is the exact same way so get out there and share it with someone. Who knows, you might just make things better for everyone.

— Adam Hawkins