I need to change this code, but it has no test!
This is the title of a talk I gave at ConFoo 2020. Can you relate?
I present a technique known under different names:
- Approval Tests
- Characterization Tests
- Golden Master
- Snapshot Tests
- Locking Tests
- Regression Tests
The purpose of the technique is to capture the existing behavior of system to create regression tests that will tell you if it changes.
It's used to quickly put Legacy Code under tests so you can refactor it safely.
Have you ever felt helpless, facing some cryptic code you had to change? You know, the kind of code that has no test to tell you if something breaks…
This is a scenario I frequently faced. And I learned better ways to work with such Legacy Code.
In this session, I'll show you how to write tests on existing code, even when you don't understand what it does. You'll learn how to modify this code and know that nothing broke when you’re done.
- Slides of my talk
- jest-extended-snapshot which provides Jest matchers to write Approval Tests
- Emily Bache's Gilded Rose kata starter in many, many languages
- Touca is a continuous regression testing tool that help you do that!
🎓 Related articles
- Can AI help me write tests on legacy code?
People are using tools like ChatGPT to write tests on existing code… But how reliable is this? Let's find out!
- 7 advice to help you inherit a legacy codebase
My recap of the most common and useful advice one can give to tackle Legacy codebases.
- Improve your refactoring and testing skills with the Expense Report kata
Watch Gregor Riegler refactor code with this coding exercise. Learn useful techniques from it.
- Can AI-based test generation help you test Legacy Code?
I experimented with tools that can generate tests for you, leveraging AI. Here is what I learned, along with some thoughts about testing unfamiliar code…
- 4 tips to refactor a complex legacy app without automation tools
How do you refactor a complex legacy application when you can't rely on automation tools?
- What's the difference between Regression Tests, Characterization Tests, and Approval Tests?
You may have heard one or the others. Now you're confused: is there a difference? Nope! Let me explain…
- Refactoring, Unit Tests, and Symmathesy
5 great talks on Legacy Code that I had the pleasure to host. Learn how to progressively migrate existing codebase towards a better state.
- Approval Tests, TCR, and Menders
5 great talks on Legacy Code that I had the pleasure to host. Learn how to test existing code and approach unfamiliar codebases.
- 5 coding exercises to practice refactoring Legacy Code
Feeling overwhelmed by your legacy codebase? These katas will help you learn how to tackle it.
- 3 steps to add tests on existing code when you have short deadlines
Here's a recipe you can follow when you want to add tests on Legacy Code, but you don't have much time to do so.
Written by Nicolas Carlo who lives and works in Montreal, Canada 🍁
He founded the Software Crafters Montreal community which cares about building maintainable softwares.