Injecting a mock of a QTimer
问题 I'm writing a unit test with QTest for a legacy code like: #include <QTimer> class MyObject: public QObject{ public: void foo(){ t1.start(500); } private: QTimer t1{this}; }; And want to mock a QTimer and then test if the QTimer::start(int) is properly called. I was trying several approaches. Dependency injection with template template<typename TIMER = QTimer> class MyObjecr: public QObject , but getting Template classes not supported by Q_OBJECT And LD_PRELOAD=libQTimerMock.so with a simple