Testing Legacy Code effectively with Approval Tests
Clare Macrae, Llewellyn Falco
You've inherited some legacy code: it's valuable, but it doesn't have tests, and it wasn't designed to be testable, so you need to start refactoring. But you can't refactor safely until the code has tests, and you can't add tests without refactoring! How can you ever break out of this loop?
Whether Legacy code for you means "old code", "code without tests", or "code you wish to redesign for new features or unit-tests", this workshop will enable you to become productive and work safely, quickly.
In this hands-on workshop, you will learn not just how to use Approval Tests to start testing legacy code, but how to create effective, maintainable, expressive tests, even on large systems.
Prerequisites
- Some prior experience of programming in C++
- The ability to run AnyDesk and Zoom, with a microphone and video camera.
- We suggest running Zoom on a second device (such as a phone or tablet)
- Optionally, a GitHub user name is helpful, for sharing code
Environment
This entire course is a workshop, with very little "lecturing", and a lot of interactive pair and group working. Our goal for this course is helping you gain Proficiency, and that requires hands-on practice.
For simplicity of setup, we will provide a virtual machine that you will be accessing via AnyDesk. It will be configured with:
- Windows
- CLion
- C++17
- Catch2
- CMake
- Git and GitHub Desktop
- A graphical diffing tool
(What we teach applies is generally applicable to a much wider range of C++ versions, IDEs, test frameworks and build systems than the above.)
Syllabus/Topics
- Testing legacy code
- Testing functional code
- Combination Testing
- Breaking the cycle of can't refactor/no tests
- Breaking up an existing application to add tests
- Approval Tests
- Write first Approval Test
- Dealing with non-stable output
- Using Approval Tests effectively, for highly maintainable tests
- Writing expressive tests
Clare Macrae
Clare is an independent consultant, helping teams work sustainably and efficiently to test and refactor legacy and hard-to-test code.
She has worked in software development for over 30 years, and in C++ and Qt for 20 years, and is now branching out to other languages.
Since 2017, Clare has used her spare time to work remotely with Llewellyn Falco on ApprovalTests.cpp, to radically simplify testing of legacy code. She has enjoyed this so much that in 2019 she set up Clare Macrae Consulting Ltd, to focus even more on helping others work with legacy code.
Before this, Clare was a Principal Scientific Software Engineer at Cambridge Crystallographic Data Centre. She is the original author of their popular C++ and Qt-based 3D crystal structure visualisation program Mercury.
Llewellyn Falco
“[After Llewellyn's coaching] I have NEVER seen our team work so well together, so much knowledge transfer and productive work!” – Tim Falleur, Healthesystems
Llewellyn Falco is an agile technical coach who specializes in teaching teams how to slay their legacy code dragons. His style is akin to a personal trainer: working with the teams to create healthy and lasting technical habits.
He is the creator of the open source testing tool ApprovalTests( www.approvaltests.com ), co-author of the Mob Programming Guidebook ( http://www.mobprogrammingguidebook.com/ ) and Co-founder of TeachingKidsProgramming.org. He is an internationally renowned speaker who has presented over 200 conference sessions since 2009.
If you would like to get a sample of him, check out his Practical Refactoring talk ( https://youtu.be/aWiwDdx_rdo )