When gmock sees a method call which it doesn't expect, it writes a warning like this:
GMOCK WARNING:
Uninteresting mock function call - returning directly.
Function call: Constructor()
Stack trace:
This is not very helpfull, when every mock object in the unit test has a method called "Constructor", since it is not always that easy to find out which object created this message and is missing an EXPECT_CALL.
It there a way to tell gmock to also write the class name or the name of the mock object in such a warning?
This is really an inconvenient.
Taking a look at the source of the uninteresting call function report, it does not seem possible to modify this behavior. And the possible reactions to a method call are given by a fixed enum, so an extension doesn't look like an option here. You could attach Google Test event listeners to the test suite, but I think that the information that reaches those is equally limited.
In my opinion, if this were really important for me, I would modify the mentioned lines of the source code of Google Mock and, along with the method name, I'd put the object address (which is the nearest thing to and identifier) with MockObject()
. Something like:
// Writes a message that the call is uninteresting (i.e. neither
// explicitly expected nor explicitly unexpected) to the given
// ostream.
virtual void UntypedDescribeUninterestingCall(
const void* untyped_args,
::std::ostream* os) const
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
const ArgumentTuple& args =
*static_cast<const ArgumentTuple*>(untyped_args);
*os << "Uninteresting mock function call - ";
DescribeDefaultActionTo(args, os);
*os << " Function call: " << Name();
*os << "Mock object address: " << MockObject();
UniversalPrint(args, os);
}
This is not as crazy as it may seem; Google Mock is a testing library, not production, so custom (controlled) modifications are not that harmful there. And actually Google does recommend use a custom compilation of Google Test for each different project.
Or you could send them the patch and see if they like it :)