Tag Archives: Software testing

Test Driven ?

TDD is a practice that I have found great success with. I have found that I became proficient in it, the name changed its meaning.

TL; DR

TDD like any skill requires time to learn and master. The meaning of the last ‘D’ in the abbreviation changes as does your mastery. As the practice becomes increasingly rote, TDD starts to become less about development and more about design.

Setup

It drives me crazy when I hear someone say “TDD is easy”. For me TDD was anything but easy. In fact, it is still easier for me to revert to coding without tests, even though I have been doing nearly everything test driven for the last 10 years.

It took me 2 years to get the hang of TDD, and 3 more to feel like I started to master it. During this time, I noticed a profound difference in my code. I spent less and less time trying to figure out what my design was. It emerged and coalesced on its own. … Well not exactly on its own.

Development

When I started, I would think about what I wanted the design to be, and write the test to prove out that design. This lead me down quite a few rabbit holes and wrong decisions. The good news was it allowed me to get better at refactoring.

As I started to get proficient in writing tests, my decisions became cleaner. My code never did, but my thought process cleared up. I would stop, and think about my tests. What does the next test highlight. What part of my design is not yet implemented. (And yes, I still got surprised when things turned out never needing to be implemented.) Here the tests were driving the development of my design. I was doing Test Driven Development.

Design

As I became even better at writing tests, I found that the questions I was asking were laborious and time consuming. I simplified them to 2 questions.

  1. Is this the API I want?
  2. What expectation is not met?

I found then that as I wrote the test to satisfy these 2 questions the design would emerge. Now a fundamental change had occurred. I was using the tests to drive my design.

 

Now a fundamental change had occurred. I was using the tests to drive my design. Click To Tweet