googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Allow naming expectations

Open rcywongaa opened this issue 3 years ago • 3 comments

Does the feature exist in the most recent commit? No

Why do we need this feature? When a test has multiple EXPECT_CALLs on the same function, it becomes difficult to determine which expectation is unmet.

Allowing the naming of expectations allows for more helpful error messages to help pinpoint which expectation failed.

Describe the proposal

Allow the specifying of name in the EXPECT_CALL

    EXPECT_CALL(my_func, Call(_)).Name("Expect my_func to be called");

which should produce the following error message on failure

Actual function call count doesn't match "Expect my_func to be called"
         Expected: to be called at least once
           Actual: never called - unsatisfied and active

Related: https://github.com/google/googletest/issues/3683

rcywongaa avatar Aug 03 '22 14:08 rcywongaa

I just tried this and I see that line numbers are printed. Does that not allow you to figure out which expectation failed?

myfile.cc:54: Failure
Actual function call count doesn't match EXPECT_CALL(c, G())...
         Expected: to be called once
           Actual: never called - unsatisfied and active

derekmauro avatar Aug 17 '22 18:08 derekmauro

Unfortunately, the line number becomes less useful if the expectations are set in a method that gets called in different places

rcywongaa avatar Aug 18 '22 09:08 rcywongaa

This can be closed now that #4041 got merged, right?

tobbi avatar May 14 '24 15:05 tobbi