TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 228 subscribers
Post #24116 22
How to Mock Any Dependency in C++

“Test Base Class Injection” is a technique that uses C++’s name resolution rules to replace a dependency at compile-time with your own test double/fake/mock.


https://github.com/MiddleRaster/tbci


It works on data-members, arguments, return types, C calls, etc. One use case is mocking a type that is an automatic variable in a static method or constructor, where subclass-and-override doesn’t work.

https://redd.it/1ogl9ur
@r_cpp
GitHub GitHub - MiddleRaster/tbci: Test Base Class Injection Test Base Class Injection. Contribute to MiddleRaster/tbci development by creating an account on GitHub.
More from @r_cpp
  1. Oct 14, 2026I tested whether a coding agent would use C++23 ranges without being told Blog post: https…
  2. Oct 14, 2026C++ futures part 1: The mental model https://devblogs.microsoft.com/oldnewthing/20261012-0…
  3. Oct 14, 2026C++ futures part 2: The mental model for std::promise, std::packaged_task https://devblogs…
  4. Oct 12, 2026[Release] slick-logger v2.2.0 — Lock-free asynchronous C++20 logging with multi-process sh…
  5. Oct 12, 2026Cheap alternative to reboot parameters (nohz, rcu, isolcpus) for stable benchmarks When no…
  6. Oct 12, 2026This C++ drama is crazy - Adobe votes no https://www.youtube.com/watch?v=DEqx_NMMH9Q https…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →