HippoMocks throws NotImplementedException when not specifying expectation

786 views Asked by At

I am investigating using mocking for unit tests I'm adding to existing code. For this I'm using HippoMocks. This involves another class calling some methods on my mock (that are all virtual). I want to avoid overspecifying all this but HippoMocks keep throwing NotImplementedException whenever the other class calls functions on my mock that I have not specified.

The below code exposes my issue.

void test()
{
    class SimpleClassToMock
    {
    public:
        virtual void memberFunction1() {}
        virtual void memberFunction2() {}
    };

    MockRepository mocks;
    // true or false here makes no difference.
    mocks.autoExpect = true;

    SimpleClassToMock* m = mocks.Mock<SimpleClassToMock>();
    // I care about this function getting called.
    mocks.ExpectCall(m, SimpleClassToMock::memberFunction1);

    m->memberFunction1();
    // HippoMocks fails on the next line by throwing NotImplementedException.
    m->memberFunction2();
}

Is there any way to tell HippoMocks not to fail here? I only want to specify the expectations for things I care about for a particular test, not every single thing that is called.

PS: To those that have mocking experience, am I thinking about this all wrong? Is overspecifying the test in cases such as this not a problem/"what you want"?

1

There are 1 answers

4
dascandy On BEST ANSWER

To avoid overspecifying, you can use OnCall to allow them to be called 0-N times (optionally with argument checks, order checks and so on).