dart-lang / mockito

Mockito-inspired mock library for Dart
https://pub.dev/packages/mockito
Apache License 2.0
635 stars 163 forks source link

Trying to set an expectation on unsupported method messes up Mockito internal state. #551

Open yanok opened 2 years ago

yanok commented 2 years ago

Currently if one generates mocks with

@GenerateMocks(customMocks: MockSpec<Foo>(unsupportedMembers: {#m})

and then trying to set an expectation on foo.m, not only the test trying to do this fails (which is expected), but also all the following tests, since unsupported method throws without cleaning _storedArgs/_storedNamedArgs and that messes up Mockito internal state.

iinozemtsev commented 2 years ago

It's broader than this, internal state is also messed if thenReturn doesn't succeed: when(mock).thenReturn(null!)

Probably no easy fix in mockito for this, but maybe an error message can be improved with possible explanations

yanok commented 1 year ago

Could be potentially fixed with https://github.com/dart-lang/mockito/issues/684. Actually I think we could get rid of internal state altogether.