r/cpp • u/According_Leopard_80 • Feb 28 '26
Mocking the Standard Template Library
https://middleraster.github.io/TBCI/MockingTheSTL.htmlWriting a test double for just one function or type in the STL can be achieved with "Test Base Class Injection" and namespace shadowing.
19
Upvotes
View all comments
Show parent comment
1
u/According_Leopard_80 Feb 28 '26
I used to do that. It’s called “Template Redefinition” in Michael Feathers’s WELC book.
It doesn’t scale (as) well, as you need more and more template parameters for the dependencies you mock, whereas TBCI always uses only one.
In the case of mocking a part of the STL, your code would have std:: on the unmocked parts, but no namespace on the mocked parts, which looks odd.