Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要模拟一个只有非虚拟方法的类。这个类有一个复制构造函数。我如何为此编写一个模拟方法。如果我只使用
MOCK_METHOD1(classname, void(classname& source));
提前致谢。
你不能用 gmock 模拟非虚函数。所以要考虑的第一个替代方案是使函数虚拟化。如果您担心使功能虚拟化的性能开销,请确保这确实是一个问题(通过测量),因为通常不是。
如果不可能使功能虚拟化,另一种解决方案是使用模板。有关此技术的详细信息,请参阅此问题,有关使用它的利弊,请参阅此问题。