Implementing C ++ and dependencies in unit testing

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 . , ?

+5
3

, Unit Testing. A B , .. A B. B , B- , , , A , , .

+8

B - , A, . B :

class A
{
    public:
        A( const B& _b ) : m_B(_b) {}

    private:
        const B& m_B;
};

B A, , B. , , , , - , , , .

, B , clone() B. , , B, MyBFactory B.

+2

, B, std:: auto_ptr . , B , .

0
source

All Articles