Thoughts on Test Driven Development

Karthikkeyan Bala Sundaram
2 min readDec 17, 2021

One of the thing I really like about test driven development is that it allows a good architecture emerge out of your code organically.

I have been told the above statement when I was introduced to test-driven development. When I heard that, I said to myself “this guy is over-romanticizing this idea”. Back then I didn’t know he means that literally. A few months later, I started realising that how good of a development strategy it is.

It has been a year since I started building software using TTD, it has been a satisfying year so far(in terms of writing code). Prior to TTD, I used to spend hours and hours, some times weeks build prototypes, to come up with an optimal architecture for a feature or a library I was asked to work. Since TTD I stopped worrying about the architecture so much as I learned and knew that a good architecture will emerge out of my code as long as I let the test drive my implementation.

Now a days when a task is given to me, my workflow goes like this,

  1. Prepare the business use cases
  2. Pick a use case and write a test which is obviously going fail(or it would not compile as there is no production code yet)
  3. Now, write production code to pass the test.
  4. Stop writing code as soon as the use case is satisfied.

Since I am writing a production code to pass a test, I have to make use of all the useful design patterns and design principles to write the production code that is testable. There are overwhelming amount of design patterns and design principles out there, but usually all we need to know is that how to hide your concrete class under a abstract interface and inject any dependency through another abstract interface. It is not limited to these two but this is where you will end up spending majority of your time.

Since you will stop writing code as soon as you are done with your test, your production code will have no dead code.

As your tests are written to implement a use case, at the end of passing a test you will be producing a working code. With TTD as your development strategy, your will be continuously producing a working code.

To learn more about TTD with practical examples, watch some of the videos from my Youtube channel. There I am doing a live coding exercise using test driven development.

Hopefully, you will find this useful.

--

--