Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use when generating mocks, stubbing methods, verifying interactions, capturing arguments, or choosing between mocks, fakes, and real objects (Mockito).
.claude/skills/evanca-mockito/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | -26% | 0% |
| case-02 | ✗→✓ | ▲ Improved | -22% | 0% |
| case-11 | ✗→✓ | ▲ Improved | -55% | 0% |
| case-18 | ✗→✓ | ▲ Improved | -6% | 0% |
| case-09 | ✓→✓ | = Same ✓ | -5% | 0% |
This skill defines how to correctly use the mockito package for mocking in Dart and Flutter tests.
| Use | When | |---|---| | Real object | Prefer over mocks when practical. | | Fake (extends Fake) | Lightweight custom implementation; override only the methods you need. Prefer over mocks when you don't need interaction verification. | | Mock (extends Mock) | Only when you need to verify interactions (call counts, arguments) or stub dynamic responses. |
verify assertions; otherwise prefer real or fake objects.dart@GenerateMocks([MyClass]) // or for nice mocks (return simple legal values for missing stubs): @GenerateNiceMocks([MockSpec<MyClass>()]) void main() { ... }
bashdart run build_runner build
test/ for mock generation by default.build.yaml if you need to generate mocks outside of test/.@override methods or implementations to a class extending Mock.dartfinal mock = MockCat(); // Return a value when(mock.sound()).thenReturn('Meow'); // Throw an error when(mock.sound()).thenThrow(Exception('No sound')); // Calculate response at call time when(mock.sound()).thenAnswer((_) => computedValue); // Return values in sequence when(mock.sound()).thenReturnInOrder(['Meow', 'Purr']);
@GenerateMocks → throws; @GenerateNiceMocks → returns a simple legal value.throwOnMissingStub(mock) to throw on any unstubbed call.dartverify(mock.sound()); // called at least once verifyNever(mock.eat(any)); // never called verify(mock.sound()).called(2); // called exactly twice
Async:
dartawait untilCalled(mock.sound()); // wait for the interaction
dart// Flexible stubbing when(mock.eat(any)).thenReturn(true); when(mock.eat(argThat(isNotNull))).thenReturn(true); // Named arguments when(mock.fetch(any, headers: any)).thenReturn(response);
null as an argument adjacent to an argument matcher.any or argThat as values, not as argument names.dartfinal captured = verify(mock.eat(captureAny)).captured; print(captured.last); // last captured argument
Use captureThat for conditional capturing.
dartreset(mock); // clear all stubs AND interactions clearInteractions(mock); // clear only recorded interactions
To mock a function type (e.g., a callback), define an abstract class with the required signature and generate mocks for it:
dartabstract class Callback { void call(String value); } @GenerateMocks([Callback])
dartlogInvocations([mock1, mock2]); // print all collected invocations
Other measured skills in the registry, with their headline benchmark lift.