
Unittest: C++ unit testing and mocking made easy - ingve
https://github.com/Manu343726/unittest#unittest
======
EdSchouten
"3\. Non intrusive arbitrary function and class mocking: No need to use
virtual function interfaces, mock classes, and dependency injection, which
couple your library design with the way the mocking framework works. unittest
uses monkey-patching through elfspy so mocking is as transparent as possible."

I think such an approach is short-sighted. It means that unit tests only end
up testing your code from a functional point of view.

By using dependency injection/mocking, unit tests also become a way of
validating that the API of your code is pleasant to work with. If your code
can be tested through mocks, it means you've written something that can be
reused, embedded and extended.

See also:
[https://en.wikipedia.org/wiki/SOLID](https://en.wikipedia.org/wiki/SOLID)

~~~
Jach
Yeah, things like "dependency injection" are generally good practice and
enable you to write unit tests _without_ a mocking framework. In the Java
world we have tools like PowerMock that rewrite bytecode to enable things like
mocking private static final methods... useful in certain circumstances, as I
assume elfspy patching is (or using LD_PRELOAD as I've seen done) but you're
almost always going to be better served by refactoring the code so you don't
need such tools.

