Gil Zilberfeld

How to TDD in legacy code

The secret to TDD in legacy code isn't just red-green-refactor. It's separating the work: first make the change possible, then make the change right.

How to TDD in legacy code
#1about 6 minutes

Why standard TDD fails in complex legacy code

Real-world code complexity and dependencies make the simple red-green-refactor cycle difficult and risky without existing tests.

#2about 3 minutes

A modified TDD process for existing codebases

A four-step approach is introduced, involving characterization tests and pre-refactoring before applying the standard TDD cycle.

#3about 7 minutes

Using characterization tests to create a safety net

Characterization tests are written to capture the current behavior of a system, including its bugs, providing a baseline for safe refactoring.

#4about 6 minutes

A step-by-step guide to fixing a bug

A bug is fixed by first writing a failing test, making the minimal code change to pass, and then refactoring both production and test code for clarity.

#5about 6 minutes

Pre-refactoring code to prepare for new features

Before adding new functionality, the code is refactored using techniques like guard clauses and switch statements to make the insertion point clear and simple.

#6about 3 minutes

Adding a new feature with the TDD cycle

After preparing the codebase, a new feature is added by writing a failing test and then implementing the minimal code required to make it pass.

#7about 5 minutes

Core principles for safe and fast development

The key takeaways are minimizing risk, separating new functionality from cleanup, and consistently leaving the code better than you found it.

#8about 9 minutes

Q&A on BDD and testing untestable code

The discussion covers the role of BDD and how to handle untestable code using tools like approval tests or snapshot testing to capture system behavior.

Related jobs
Jobs that call for the skills explored in this talk.

test

Milly
Vienna, Austria

Intermediate

test

Milly
Vienna, Austria

Intermediate

Featured Partners

Related Articles

View all articles
DC
Daniel Cranney
The real reason we document our code
The world of software development moves fast. Technology is constantly changing, as are the tools we use with it, and even the role of a programmer is itself constantly in flux. However, some aspects of software engineering are so foundational that w...
The real reason we document our code
CH
Chris Heilmann
Dev Digest 136 - No JS(on) of mine
News and ArticlesDouglas Crockford is our featured video, so let's talk about evolving JavaScript and all things JSON. Judicious JSON explains all the weird things in it, you can learn why it can be incredibly slow, people wonder what even is a JSON ...
Dev Digest 136 - No JS(on) of mine
CH
Chris Heilmann
Dev Digest 125 - Duck and Cover
This issue was written live at the WeAreDevelopers World Congress in Berlin with us being incredibly busy, but this shouldn't mean you don't get some hot resources. News and ArticlesLet's start with AI news: Google and Microsoft consume more power th...
Dev Digest 125 - Duck and Cover

From learning to earning

Jobs that call for the skills explored in this talk.

Code cleaner

Code cleaner

Cleanup Services
Rome, Italy

Remote
45-50K
Intermediate
PHP
JavaScript