Member-only story

Gradually Transforming All Legacy Code with TDD

Can you do TDD With Legacy Code? What kind of strategies can you follow?

David Rodenas PhD
8 min readMay 17, 2022
Girona seen from a bridge over the Onyar, and the inspiration for this article.
Girona seen from a bridge over the Onyar, and the inspiration for this article. Photo by Fikri Rasyid on Unsplash

I have done several talks about TDD, and I have been helping several teams to start working with TDD. And almost every time I receive the same question: If my legacy codebase does not have any developer tests, how can I start doing TDD?

How TDD Works?

TDD is a style of programming that combines coding, testing, and design. It works as a discipline, in which the programmer follows three rules:

  1. The developer writes the test before implementing the code, until the test fails.
  2. The developer writes the minimal amount of code that makes the test pass.
  3. While making the tests pass frequently, the developer refactors the test and production codes.

These three rules repeats frequently, executing the tests several times each minute. While following the Agile principle of simplicity (the art of maximizing the work not done), these rules aim to reduce the Technical Debt.

Legacy Code

The term «Legacy Code» usually refers to an old code that is no longer in active development, but sometimes it also can be understood like code without…

--

--

David Rodenas PhD
David Rodenas PhD

Written by David Rodenas PhD

Passionate software engineer & storyteller. Sharing knowledge to advance our skills. Join me on a journey of discovery in the world of software engineering.

Responses (2)