Google Mock Class Constructor with parameters depending on other objects

500 views Asked by At
  class MockBaseClass : public BaseClass
  {

    public:
    // Constructor
    MockBaseClass(MockDep1 * pA)
     :BaseClass( pA)
    {
       mpA = pA;
    }

MockDep1 is a mock for Dep1

BaseClass

BaseClass(Dep1 *pA) { ..... mpX = new X(pA->getCollection()->getA());//crashes }

How can I avoid this situation? I tried to make a mock for X class but I don't know how to use it because the constructor of the Base Class is called anyway.

1

There are 1 answers

0
Adelina On

I solved it by mocking the methods from MockDep1