如何在 Google Mock 中模拟带有可选参数的方法?例如: 我尝试了这个,但它不起作用:
template <typename T>
class A
{
public:
virtual void set_enable(const int test, const bool enabled = true ) const;
};
template <typename T>
class MockA : public A<T>
{
MOCK_CONST_METHOD2_T( set_enable, void(const int test, const bool enabled ) );
void set_enable(const int test /*, const bool enabled = true*/ ) const
{
set_enable( test, true);
}
};
然后致电:
MockA mockA;
EXPECT_CALL(mockA, set_enable(_,true)).Times(Exactly(1));
当我运行测试时,它显示“分段错误”
不确定如何标记为如何在 Google Mock 中使用可选参数模拟方法?或考虑文档https://google.github.io/googletest/gmock_cook_book.html作为旧版本的 gmock 的副本虽然这个特定的问题与我目前正在试图弄清楚的事情是一致的。