MATCHERs vs ACTIONs for printing details about large structures that didn't match

Skip to first unread message

Maurice van der Pot

Aug 10, 2016, 10:48:30 AM8/10/16
to Google C++ Mocking Framework
In some of our tests we expect a single call to a function that has a large structure as an input parameter. We want to test if a subset of the members of this structure are set to certain values. Because the structure is so large, we are interested in knowing which fields differed if the expectation didn't match.

We could create a matcher with the MATCHER macro, but if the expectation is not matched we can only see the generic message for this matcher.
We could add prints to the matcher (and it will work in our case), but matchers are not supposed to have side-effects because they may be evaluated multiple times.
Alternatively we could accept any value for the structure in the expectation (testing::_) and define an ACTION that prints how the actual structure differs from the one we expect.
Maybe there are other options that I haven't considered.

What would be the best way to deal with this situation?

Best regards,

Samuel Benzaquen

Aug 10, 2016, 3:29:56 PM8/10/16
to Maurice van der Pot, Google C++ Mocking Framework
Matchers can return textual results on failure.
The MATCHER* macros provide an implicit argument 'result_listener' of type std::ostream*


Best regards,


You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit

Reply all
Reply to author
0 new messages