What problem does it solve?
Managing mocks and stubs in Flutter/Dart tests manually is error-prone and repetitive. Mockito provides a structured way to generate mocks, verify interactions, and capture arguments, reducing boilerplate and increasing test reliability.
Core Features & Use Cases
- Mock generation: Use @GenerateMocks to create mock classes for your Dart interfaces or concrete classes.
- Stubbing and verification: Define return values and verify interactions to ensure correct method usage.
- Argument capture and matchers: Capture call arguments and use matchers to assert expectations across multiple calls.
- Test utilities: Use reset and clearInteractions to manage mock state between tests; mock function types and async support for Flutter tests.
- Advice on real vs fake vs mock: Prefer real or fake implementations when possible; reserve mocks for interaction verification and behavior stubbing.
Quick Start
Annotate your test class with @GenerateMocks([YourClass, AnotherClass]) and run dart run build_runner build to generate the mock classes.