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.

Featured Partners

Related Articles

View all articles
DC
Daniel Cranney
Dev Digest 195: End of Likes, JavaScript’s a Zoo, and Messing with Bots!
Inside last week’s Dev Digest 195 . 👎 No more external likes 🤗 Needy programs 📉 The worst selling Microsoft product 🟨 JavaScript engines zoo 🍞 No more toasts! 🤖 Messing with bots 👔 Beware of fake job interviews 🗞️ Join over 150,000 developers alread...
Dev Digest 195: End of Likes, JavaScript’s a Zoo, and Messing with Bots!
BR
Benjamin Ruschin
What Developers Really Need to Create Great Code Demos
Every developer on earth has, at some point, had another developer to thank for a breakthrough, a success, an aha moment they wouldn’t have had without coming across that blog post, that open-source contribution, that reply on socials or that humble ...
What Developers Really Need to Create Great Code Demos
DC
Daniel Cranney
How to Avoid Over-Engineering
In today’s software development world, the demand for designing applications that are both robust and easy to maintain is more pressing than ever. Many developers encounter the architectural chaos left behind in older codebases, leading to frustratio...
How to Avoid Over-Engineering
DC
Daniel Cranney
Exploring TypeScript: Benefits for Large-Scale JavaScript Projects
JavaScript is the backbone of web development, powering everything from small websites to large-scale enterprise applications. However, as projects grow in complexity, maintaining JavaScript code can become increasingly difficult. This is where TypeS...
Exploring TypeScript: Benefits for Large-Scale JavaScript Projects

From learning to earning

Jobs that call for the skills explored in this talk.

Software Engineer

Software Engineer

tree-IT GmbH
Bad Neustadt an der Saale, Germany

54-80K
Intermediate
Senior
Java
TypeScript
Spring Boot
Java Software Engineer

Java Software Engineer

Test Driven Solutions
Edinburgh, United Kingdom

Intermediate
Java
MySQL
NoSQL
Scrum
Jenkins
+4
Creative Javascript

Creative Javascript

Thegiglab
Amsterdam, Netherlands

Intermediate
API
CSS
HTML
jQuery
Bootstrap
+1