GMOCK ON_CALL how to select right overloaded mock #4567
Unanswered
zokroj
asked this question in
Community Help
Replies: 1 comment
-
The issue you're facing is because To resolve this, you need to disambiguate the call by explicitly specifying the method signature in the Here's how you can do it:
ON_CALL(mock, request(static_cast<const Type1&>(_)))
.WillByDefault(testing::Invoke([&](){ })); Or, for the other overload: ON_CALL(mock, request(static_cast<const Type2&>(_)))
.WillByDefault(testing::Invoke([&](){ }));
ON_CALL(mock, request(testing::A<const Type1&>()))
.WillByDefault(testing::Invoke([&](){ })); This way, the compiler knows exactly which overloaded method you're referring to, and it should eliminate the ambiguity. Let me know if this resolves the issue! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am having issues trying to use ON_CALL with overloaded methods. I have something like the following:
MOCK_METHOD(RequestResult, request, (const Type1 a));
MOCK_METHOD(RequestResult, request, (const Type 2 &b));
When I set the ON_CALL like this:
ON_CALL(mock, request(_)).WillByDefault(testing::Invoke([&](){ }));
the compiler is complaining about call to be ambiguous, if I try to use the Matchers:
ON_CALL(mock, request(testing::A<Type1>()).WillByDefault(testing::Invoke([&](){ }));
I get the following:
note: candidate function not viable: no known conversion from 'Matcher<>' to 'const ::testing::internal::WithoutMatchers' for 1st argument
I am using gtest version 1.11 - any hints?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions