3 ms·
In C++, you normally don't -- there are low-level function hooking calls or ptrace api, but those are too complex to be used in unit tests. The approaches I ha
by theamk 3y ago
In C++, you normally don't -- there are low-level function hooking calls or ptrace api, but those are too complex to be used in unit tests.
The approaches I have seen used in practical projects is:
Ignore unit testing of time-related parts, rely on integration tests.
Have unit tests be super slow so that actual system clock can be used. Get occasional false positive failures when your build system scheduled unit tests in parallel with particularly complex compilation tasks.
Wrap everything in your own wrapper, providing "production" and "testing" version of class, which "production" calling into the 3rd party library while "testing" calls into your implementation that uses debug time. This is non-trivial as "testing" implementation might be quite complex, but may be worth it for some common functionality like timers.