Mock non-virtual method C++ (gmock)(模拟非虚方法 C++ (gmock))
问题描述
我有课
请你帮助如何模拟 MethodA()
而不使虚拟,我不明白 高性能依赖注入 的概念 p>
Please can you help how to mock MethodA()
without making virtual,
I didn't understand the concept of hi-perf dependency injection
推荐答案
这意味着你必须模板化你的生产代码.使用您的示例:
It means you will have to templatize your production code. Using your example:
CSumWind
类定义:
模拟CSumWnd
类定义:
必须使用模拟类 CSumWind
测试的生产类.现在它被模板化以提供在生产代码中使用 CSumWind
类和在测试中使用 MockCSumWnd
类.
Production class which have to be tested with mocked class CSumWind
. Now it becomes templated to provide using CSumWind
class in production code and MockCSumWnd
class in tests.
TestedClass
在生产环境中的实例化:
Instantiation of TestedClass
in production:
在测试可执行文件中实例化 TestedClass
对象:
Instantiation of TestedClass
object in test executable:
这篇关于模拟非虚方法 C++ (gmock)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!