I am effectively calling a method of a mocked class 3 times in a test but when I assert that the call was method 3 times, the test fail. The actual call count is down to 1 according to the result from 2. How does mockito counts calls ?
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
class RealService {
doSomething(){
}
}
class MockService extends Mock implements RealService{}
void main() {
test('Mockito callcount 3 times',(){
final mock = MockService();
mock.doSomething();
mock.doSomething();
verify(mock.doSomething()).called(2);
// now calling a third time again
mock.doSomething();
verify(mock.doSomething()).called(3);
});
}
My background is from sinon
in Node
Expected: <3>
Actual: <1>
Unexpected number of calls
Mockito has a reset function that does exactly this.
Use clearInteractions to clear just the call count, reset clears call count and stubs, so you'll need to restub.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With