, .
:
myDataClass . 2 , "" .
mock 2 , "myDataClass", - . . .
class myWorkerClass {
public:
myWorkerClass(myDataClass * dc) : m_dc(dc) {}
myWorkerClass() : m_dc(new MyRealDataClass()) { }
~myWorkerClass { delete m_dc; }
private:
myDataClass *m_dc;
}
myDataClass myWorkerClass, . , "" .
Another method would be to use the Factory pattern to instantiate your objects. Your test code could set some flag in Factory, which creates instances of myDataClass and creates a mock object for it instead of the real one. I prefer the first technique, as it’s a little easier for me to use (plus I don’t need to support the Factory class for everything I want to check)
source
share