
Dart generate test mocks
Teaches agents to write Dart unit tests with generated Mockito mocks via build_runner
Dart generate test mocks is an open-source agent skill for developer tools. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.
- Scripts
- None
- Platforms
- Claude Code, Codex, Cursor
- GitHub stars
- 3.2K
- Last commit
- License
- BSD-3-Clause
- Listing updated
Similar skills
About Dart generate test mocks
This skill guides an agent through testing Dart code that talks to outside services such as HTTP APIs or databases. It explains how to structure classes so their dependencies can be injected and swapped for test doubles, and how to set up the pubspec with test, mockito and build_runner as dev dependencies.
The workflow covers annotating a test file with GenerateNiceMocks and MockSpec, running build_runner to produce the .mocks.dart file, then stubbing with when and thenAnswer for asynchronous calls and checking interactions with verify. It also includes a troubleshooting loop for common failures such as unexpected null results or build_runner import mismatches, and a worked example that mocks an http.Client.
The skill assumes a Dart project and works with the test package, package:mockito and build_runner. It is part of the Flutter agent plugins repository and is released under the BSD-3-Clause license.
When your agent uses it
Define and generate mock objects for external dependencies using `package:mockito` and `build_runner`. Use when unit testing classes that depend on complex external services like APIs or databases.
From the skill's SKILL.md. Your agent reads this description to decide when to load the skill.
What it can access
- Instructions only, no scripts(see the files on GitHub)
- License: BSD-3-Clause(see the files on GitHub)
From a static check of its 1 file (6 KB) on GitHub on 1 December 2026. Nothing was run. Read the files before you install a skill: it can tell your agent to run anything its tools allow.
Check another skill before you install it.
Install
This skill ships in the dart-flutter plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):
/plugin marketplace add flutter/agent-plugins
/plugin install dart-flutter@dart-flutterOr copy only this skill to ~/.claude/skills/dart-generate-test-mocks:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/flutter/agent-plugins.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/dart-generate-test-mocks &&
cp -R "$tmp/skills/dart-generate-test-mocks" ~/.claude/skills/dart-generate-test-mocks &&
rm -rf "$tmp"For one project only, put the folder in .claude/skills/dart-generate-test-mocks inside it instead.
Copy the skill folder to ~/.agents/skills/dart-generate-test-mocks to use it in every repository:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/flutter/agent-plugins.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/dart-generate-test-mocks &&
cp -R "$tmp/skills/dart-generate-test-mocks" ~/.agents/skills/dart-generate-test-mocks &&
rm -rf "$tmp"For one repository only, put the folder in .agents/skills/dart-generate-test-mocks inside it instead.
Copy the skill folder to ~/.cursor/skills/dart-generate-test-mocks to use it in every project:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/flutter/agent-plugins.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/dart-generate-test-mocks &&
cp -R "$tmp/skills/dart-generate-test-mocks" ~/.cursor/skills/dart-generate-test-mocks &&
rm -rf "$tmp"For one project only, put the folder in .cursor/skills/dart-generate-test-mocks inside it instead.
Run in a terminal (add --scope workspace to install it for the current workspace only):
gemini skills install https://github.com/flutter/agent-plugins.git --path skills/dart-generate-test-mocksOr copy the folder to ~/.gemini/skills/dart-generate-test-mocks yourself.
For GitHub Copilot in VS Code, copy the skill folder to ~/.copilot/skills/dart-generate-test-mocks:
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/flutter/agent-plugins.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/dart-generate-test-mocks &&
cp -R "$tmp/skills/dart-generate-test-mocks" ~/.copilot/skills/dart-generate-test-mocks &&
rm -rf "$tmp"For one project only, put the folder in .github/skills/dart-generate-test-mocks inside it instead.
Get the folder:
git clone --depth 1 https://github.com/flutter/agent-plugins.gitThen copy agent-plugins/skills/dart-generate-test-mocks into your agent's skills folder as dart-generate-test-mocks. Agents that support SKILL.md read one folder per skill.
What it does
- Dependency injection setup
- Shows how to pass external clients like http.Client through constructors so they can be replaced during tests.
- Mock generation with build_runner
- Covers annotating test files with GenerateNiceMocks and generating the mock classes with a single build command.
- Async stubbing rules
- Explains when to use thenAnswer instead of thenReturn for Future and Stream results.
- Interaction verification
- Describes using verify, call counts and argument matchers such as any and captureAny.
- Test failure troubleshooting
- Lists common mock and build_runner errors and how to resolve them step by step.
- Worked HTTP client example
- Provides a complete service class and test file that mock an http.Client with success and error responses.
Good for
- Write unit tests for a class that calls a REST API in Dart
- Mock a database access layer so tests run without a real database
- Generate mock classes for a Dart service using build_runner
- Stub an asynchronous method and verify how many times it was called
- Fix a failing Dart test caused by a missing mock stub
Dart generate test mocks FAQ
What packages does Dart generate test mocks require in a Dart project?
It uses package:test, package:mockito and build_runner as dev dependencies, plus any runtime packages such as package:http that the code under test depends on.
Why does the skill recommend GenerateNiceMocks over GenerateMocks?
According to the skill, GenerateNiceMocks avoids missing stub exceptions, so unstubbed calls return default values instead of failing the test.
Which mocking command does the skill use?
It runs dart run build_runner build to generate the mock files, and dart test to run the suite.
When should thenAnswer be used instead of thenReturn?
The skill says to use thenAnswer with an async function for methods that return a Future or Stream, and not thenReturn.
How do I install Dart generate test mocks in Claude Code?
Copy the skill folder from GitHub to ~/.claude/skills/dart-generate-test-mocks to use it in all your projects, or to .claude/skills/dart-generate-test-mocks in one project. Or install the dart-flutter plugin, which includes it: /plugin marketplace add flutter/agent-plugins, then /plugin install dart-flutter@dart-flutter.
Does Dart generate test mocks run scripts?
No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.
Which AI agents can use Dart generate test mocks?
Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.
What are the best alternatives to Dart generate test mocks?
The closest alternatives to Dart generate test mocks are Dart add unit test, Flutter testing skill, Dart flutter patterns, Flutter add widget test and Flutter add integration test.
Where this comes from
- Description: from the skill's own SKILL.md.
More from flutter/agent-plugins

Guides your agent to write and organize Dart and Flutter unit tests with package:test
- Open source
- 3.2K GitHub stars
- Developer tools

Sets up Flutter integration tests and turns MCP-driven UI exploration into repeatable
- Open source
- 3.2K GitHub stars
- Developer tools

Guides the agent to write Flutter widget tests with WidgetTester for taps, scrolling
- Open source
- 3.2K GitHub stars
- Developer tools

Review Dart or Flutter API code against canonical API design principles
- Open source
- 3.2K GitHub stars
- Developer tools

Write clear docstrings, dartdoc and JSDoc for Dart, Python and TypeScript
- Open source
- 3.2K GitHub stars
- Files and documents

Run a multi-step pull request or local diff review with critique and synthesis
- Open source
- 3.2K GitHub stars
- Developer tools



