Working with C++ Legacy Code
summary
Shows a concrete workflow: write unit tests to capture behavior, then remove hard dependencies using Google Test and Google Mock, and finally refactor. Demonstrates faking an HTTP client and database in a distributed calculator and a TripService example, using template duck-typing to replace static/unmockable code and a replace singleton instance trick (via friend access) to inject test doubles. Tests run locally, failures reveal missing calls, and after applying these techniques the author gets passing tests and incremental, safe refactors.
AI-written summary · about
chapters (15)
- 0:00Intro
- 3:20No longer engineered - continuedly patched
- 5:14Written by someone else
- 7:20The good news and bad news
- 9:07Gaining control over legacy code
- 11:56This is a unit test (GTest)
- 14:52A quick reality check
- 16:34Sensing and Separation
- 18:22The solution-fake/mock objects
- 19:20Fake objects using Google Mock
- 27:20Non virtual methods
- 37:54Problem: un-fakeable methods
- 41:48Using templates for injection
- 44:12Faking Private and Protected Methods
- 46:52Taking control of existing legacy code
related talks
45mWorking with C++ Legacy Code
01h 01mYou Can Test Anything
38mSurgical Refactoring of Non-Tested Code – A Worked Example
46mTestability and C++ API Design
01h 01mBack to Basics: Test-driven Development
01h 22mTest-Driven Development of C++ Embedded and System-Level Software
01h 17mRefactoring Legacy C++ OOP Application Code with Functional Programming and Type Erasure Concepts
42mWorking Effectively with (Android) Legacy Code
