mock icon indicating copy to clipboard operation
mock copied to clipboard

`t.Helper()` equivalent for mocks

Open qdm12 opened this issue 2 years ago • 1 comments

Requested feature Mark a mock configuration helper function as such so that error traces point back to the call to this mock configuration helping function instead of the call to EXPECT().

Why the feature is needed Error logs will always show the trace pointing to the EXPECT() call even if it is in a shared mock configuration helping function. As far as I have searched, there is no way to mark a 'mock configuration helper function' as such even if using t.Helper().

(Optional) Proposed solution

  • Detect when t.Helper() has been called and adapt error stack traces with it, or
  • Define a new method Helper() on the controller, or
  • Define a new method Helper() on generated mocks

qdm12 avatar Mar 01 '22 20:03 qdm12

I think in order to not change expectations on how people use the library today it would need to be your second or third idea. I would not want to change existing call stacks without more research. I will leave this issue open to see if it gets traction from more in the community.

codyoss avatar Apr 24 '22 19:04 codyoss