Suppose I have a C ++ class:
class A { public: A() { } void SetNewB( const B& _b ) { m_B = _b; } private: B m_B; }
To make the unit test something like this, I would have to break the dependency on B. Since class A takes place for the actual object and not for the pointer, I would have to reorganize this code to take the pointer. Also, I will need to create a parent interface class for B so that I can pass my own fake B when I test SetNewB.
? B, , ( ). , B - , , B?
, , A . , ?
, Unit Testing. A B , .. A B. B , B- , , , A , , .
B - , A, . B :
B
A
class A { public: A( const B& _b ) : m_B(_b) {} private: const B& m_B; };
B A, , B. , , , , - , , , .
, B , clone() B. , , B, MyBFactory B.
clone()
MyBFactory
, B, std:: auto_ptr . , B , .