mockito

Generate and verify mocks in Flutter/Dart tests with Mockito.

611|60|Updated Apr 22, 2025
One-click install
npx skills add https://github.com/evanca/flutter-ai-rules --skill mockito
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mockito
Source: https://github.com/evanca/flutter-ai-rules/tree/main/skills/mockito
Command: npx skills add https://github.com/evanca/flutter-ai-rules --skill mockito

SYSTEM DOCUMENTATION & REQUIREMENTS

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.

Frequently Asked Questions about mockito

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate mocks for Flutter unit tests using Mockito?

To generate mocks for Flutter unit tests, annotate your test file with @GenerateMocks and run dart run build_runner build. This process creates mock classes that enable controlled behavior and interaction verification for your Dart dependencies.

How do I verify interactions and capture arguments in Dart Mockito tests?

You verify interactions and capture arguments in Dart Mockito tests using the verify and capture utilities. These features allow you to assert method usage and extract call arguments across multiple synchronous and asynchronous test flows.

Does Mockito work with asynchronous Flutter widget tests?

Yes, Mockito works with asynchronous Flutter widget tests by providing dedicated async support. It allows you to stub return values and verify interactions for dependencies that execute across both synchronous and asynchronous test flows.

When should I use mocks instead of real or fake implementations in Dart testing?

You should use mocks instead of real or fake implementations in Dart testing primarily when you need interaction verification and behavior stubbing. Prefer real or fake implementations whenever possible to increase test reliability and reduce boilerplate.

How do I reset mock state between Flutter tests?

You reset mock state between Flutter tests using the reset and clearInteractions utilities. These test utilities clear stubbed behaviors and recorded interactions, ensuring a clean and isolated testing environment for each subsequent test run.