How TDD model a better code

Published Nov 28, 2017

Everyday more and more teams work using Test-Driven Development and that is great! But most of the time TDD is sold as a method to "decrease code failure". If you code with that in mind, one of the main benefits of TDD is lost: better code.

By better code I mean more legibility, fewer complex solutions, more usual structures and, of course, fewer bugs. Most of this can be easily accomplished if you use TDD the right way. The best way to learn it is using coding dojos and experience.

When you start with tests, many new and misguided things come to surface, such as integration tests, unit tests and others. You can read a lot about testing, but there's nothing like real life experience to learn what to use and how to use it.

I was working on a project with a new developer who was unfamiliar with tests, but he read a lot about it. The thing is his code was often overly complex and sometimes the tests don’t cover the errors they need to. After some pair programming time, we could sort that out.

Real life experience is essential to start really using TDD, writing tests first with confidence and accomplishing better code in the end. Pair programming and coding dojos are excellent ways to promote it.

Discover and read more posts from Thiago Garcia
get started