stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
22.52k stars 1.56k forks source link

Very confusing output if call.Repeantability exceeded #514

Closed decibel closed 4 months ago

decibel commented 6 years ago

If too many calls with the same exact inputs happen, the error report is extremely confusing:

mock: Unexpected Method Call
---------------------------

MyFunc(...)
   0: 'a'

The closest call I have is:

MyFunc(...)
   0: 'a'

I think the best way to handle this would be for Mock.MethodCalled() to include closestCall.totalCalls in it's output somehow. Is there a better way?

It would also be nice to report how many calls have already occured, vs how many were originally allocated, but that's hard to do since Repeatability gets modified. It seems that Repeatability could just be left alone and totalCalls compared to it, no?

ernesto-jimenez commented 6 years ago

The whole setup to keep track of calls is quite messy because the original package exposed too much of its internals like Repeatability, which means we cannot change that behaviour without introducing a breaking change.

We can definitely improve on the error message and specify that calls have been exhausted on the closest call.

Something like:

mock: Unexpected Method Call
---------------------------

MyFunc(...)
   0: 'a'

The closest call I have is:

MyFunc(...) - Total calls received: 3 (maximum reached)
   0: 'a'
st3penta commented 4 months ago

Closed by https://github.com/stretchr/testify/pull/767