Search code examples
googletestgooglemock

google mock - how to expect function to NOT be called with set of parameters


Let's say you have void Class::func(Type_t arg)

I want to say

this function can be called except with arguments arg1 or arg2 or ... argN

Is this the correct way?

EXPECT_CALL(Class_MockObj, func(arg1)).Times(0);
EXPECT_CALL(Class_MockObj, func(arg2)).Times(0);
...
EXPECT_CALL(Class_MockObj, func(argN)).Times(0);

FEEL FREE TO COME UP WITH A BETTER TITLE FOR QUESTION


Solution

  • You can also write this using AnyOf:

    EXPECT_CALL(Class_MockObj, func(AnyOf(arg1, arg2, .., argN))).Times(0);