There is a singleton class for covering tests using the gmock framework . Some methods (such as method1 () in the example) change the class field values during a call. Is there any way to set default values to class fields without changing the class structure?
Example:
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; };
static TestingClass& Instance()- goldstar_labs