Will your program still be correct next year?
summary
Implementing a words-per-count histogram, the code evolves from manual prints to automated assertions and then to real frameworks: doctest, Catch2, and GoogleTest (using death tests). Refactors replace std::map with unordered_map plus a transparent hasher for tens of thousands of strings, and a freestanding for_each_word plus std::views::split exposes edge cases. Tests find order assumptions, separator corner cases, and an assert-on-remove design flaw; replacing the assert with a pluggable violation handler or returning counts fixes behavior and survives CI.
AI-written summary · about
chapters (27)
- 0:00Introduction
- 1:10Histogram implementation and testing
- 4:25Manual testing limitations
- 5:51Types of tests
- 7:59Test result recipients
- 9:03Test failure outcomes
- 11:29Test properties and expectations
- 13:16Improving tests with requirements
- 15:02Introducing doctest
- 17:10Expanding histogram functionality
- 18:57Behavior-driven development
- 21:04Range behavior and order testing
- 22:11Switching to Catch2
- 24:45Performance improvements
- 27:23Generalizing tests
- 27:46Inserting and removing words
- 29:11Testing private functions
- 31:41Benefits of standalone testing
- 33:32Refactoring with C++20 split
- 35:19Testing asserts and termination
- 38:13Mocking and violation handlers
- 41:09Testing violation handlers
- 44:00Testing remove operations
- 47:35Wrap-up and testing principles
- 50:47Flaky tests dangers
- 52:13Long-term test importance
- 53:18Further learning recommendations
related talks
56mWill Your C++ Program Still Be Correct Next Year?
01h 02mBack to Basics: Unit Tests
52mNobody Can Program Correctly - Lessons From 20 Years of Debugging C++ Code
59mC++ Unit testing - the good, the bad & the ugly
01h 32mFuture of Testing With C++20
53mC++ Unit testing - the good, the bad & the ugly
38mSurgical Refactoring of Non-Tested Code – A Worked Example
58mTest Driven C++ with Catch
