我有使用gmock 框架进行测试覆盖的单例类。某些方法(例如示例中的 method1())在调用期间会更改类的字段。有没有办法在不修改TestingClass的情况下为类的字段设置默认值?
例子:
class TestingClass
{
private:
TestingClass(): _field1(0)
, _field2(0)
{
}
TestingClass(const TestingClass&){}
TestingClass & operator=(const TestingClass &){}
public:
static TestingClass Instance()
{
static TestingClass instance;
return instance;
}
void method1()
{
_field1 = 777;
}
void method2()
{
_field1 = 888;
}
void Show()
{
std::cout << "\nField1 - " << _field1
<< "\nField2 - " << _field2
<< "\n";
}
//other methods...
private:
int _field1;
int _field2;
};