called method Null safety

void called(
  1. dynamic matcher

Assert that the number of calls matches matcher.


  • verify(mock.m()).called(1) asserts that m() is called exactly once.
  • verify(mock.m()).called(greaterThan(2)) asserts that m() is called more than two times.

To assert that a method was called zero times, use verifyNever.


void called(dynamic matcher) {
  if (!_testApiMismatchHasBeenChecked) {
    // Only execute the check below once. `Invoker.current` may look like a
    // cheap getter, but it involves Zones and casting.
    _testApiMismatchHasBeenChecked = true;
  expect(callCount, wrapMatcher(matcher),
      reason: 'Unexpected number of calls');