HippoMock: taunts part of the class

I would like to know if with HippoMock you can mock part of the class.

Example

class aClass
{
public:
    virtual void method1() = 0;

    void method2(){ 
        do
            doSomething;      // not a functon 
            method1();
        while(condition);
    };
};

I would like to make fun of only method1 to test method 2

It’s clear that I am using HippoMock, and I have an error in method2, so I did a unit test to fix this and make sure it won’t return. But I did not find a way to do this.

I try this

TEST(testMethod2)
{
    MockRepository mock;
    aClass *obj = mock.Mock<aClass>();
    mock.ExpectCall(obj , CPXDetector::method1);
    obj->method2();
}

Is there any solution in native cpp? With a different wireframe layout?

Thank you so much

Ambroise petitgenêt

+3
source share
1 answer

. -, , . -, , - , , .

? , Hippomocks , , , , . - , , , :

class bClass : public aClass
{
    int _counter;
public:
    bClass() : aClass(), _counter(0){}
    void method1() { _counter++; }
    int NumCallsToMethod1() const { return _counter; }
};

TEST(testMethod2)
{
    bClass testThis;
    testThis.method2();
    TEST_EQUALS(1,testThis.NumCallsToMethod1());
}

, method1 const:

class bClass : public aClass
{
    mutable int _counter;
public:
    bClass() : aClass(), _counter(0){}
    void method1() const { _counter++; }
    int NumCallsToMethod1() const { return _counter; }
};
+1

All Articles