dart-generate-test-mocks Skill for Claude Code: Mockito
Makes your agent generate mockito mocks with build_runner and write unit tests for Dart classes that depend on APIs or databases.
- Installs
- 18.8K
- on skills.sh
- Stars
- 537
- on GitHub
- Updated
- Oct 2026
- last repo commit
The skill gives the agent a ten-step checklist for mocked tests. Inject the dependency through the constructor, annotate the test file with @GenerateNiceMocks, run build_runner, then stub, run the code and verify. It insists on thenAnswer for anything that returns a Future or Stream, and says thenReturn must never be used there.
It loads when you unit test classes that depend on external services. It needs the Dart SDK and adds mockito, build_runner and test as dev dependencies. The skill includes a full worked example with an http.Client.
Good for
- Dart developers who need to unit test code that calls an API or database
- Teams whose Dart code calls an http client and needs tests that do not hit the network
- Anyone fixing "missing stub" or async mock errors in mockito tests
Install dart-generate-test-mocks
Claude Code
- 1
Copy this prompt.
Install the dart-generate-test-mocks skill in Claude Code. Run this command: npx skills add https://github.com/dart-lang/skills --skill dart-generate-test-mocks Then check that it loaded and tell me how to use it.
- 2
Paste it into Claude Code. It shows the change and asks before running it.
Requires Node.js.
From its listing on skills.sh. Source.
What's in the skill
When it loads
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.
Sections in SKILL.md
- Contents
- Structuring Code for Testability
- Managing Dependencies
- Generating Mocks
- Implementing Unit Tests
- Workflow: Creating and Running Mocked Tests
- Task Progress
- Feedback Loop: Test Failures
- Examples
- High-Fidelity Mocking and Testing Example
Key facts
- Author
- Dart team (dart-lang)
- Installs on skills.sh
- 18,807 as of 2026-11-02
- GitHub stars
- 537 for the whole dart-lang/skills repo
- Last repo commit
- 2026-10-16
- What is inside
- 1 file including SKILL.md
- skills.sh audits
- Gen Agent Trust Hub: pass; Socket: pass; Snyk: pass
What it includes
Inject the dependency through the constructor
Refactors a class so external services such as an http client come in through its constructor. URLs are passed as Uri objects.
Write ·
Structure code for testingAdds http, test, mockito and build_runner
Uses dart pub add for the runtime package and for the three dev packages. The http library is imported with a prefix to avoid name clashes.
Runs code ·
Manage dependencies@GenerateNiceMocks plus build_runner
Puts the annotation with MockSpec entries in the test file, imports the generated .mocks.dart file and runs the build_runner build command. It prefers nice mocks to avoid missing-stub exceptions.
Runs code ·
Generate mockswhen, thenAnswer, verify, argument matchers
Stubs sync methods with thenReturn and async ones with thenAnswer. It checks calls with verify and called(n), and uses any, anyNamed and captureAny for flexible matching.
Write ·
Stub and verifyRun, read the error, fix, repeat
If a mock throws an unexpected null error it checks for nice mocks. If an async stub throws an ArgumentError it swaps thenReturn for thenAnswer. If build_runner fails it checks the .mocks.dart import name.
Runs code ·
Test failure feedback loop
From the official docs
Permissions
Low risk
It edits your code and pubspec.yaml and runs a code generator and your tests. Review the diff, and commit the generated mock files only if your project tracks generated code.
What it can do
- Read your data
- Create and change things
- Delete things
- Read-only mode
Watch out for
It adds dependencies and generated files
The skill adds four packages and generates .mocks.dart files. Review the pubspec and the generated files before you commit them.
Security advisories
No published security advisories as of Nov 2, 2026.
Technical details
| Turning on read-only | No read-only mode. The skill edits code, adds dependencies and generates files. |
|---|---|
| Talks to | Adding packages runs pub commands that fetch them |
| Scopes |
|
Questions
What does dart-generate-test-mocks do?
It makes your agent create mock objects with mockito and build_runner, then write unit tests that use them. It targets classes that depend on APIs, databases or other external services.
How do I install it?
Use the install box at the top of this page. It lists the options for Claude Code, Codex and other tools.
Does it need an API key or an account?
No. Its SKILL.md names no API key, account or sign-in. It uses the Dart or Flutter tools already on your machine.
Why does it say never to use thenReturn for async methods?
SKILL.md marks this as critical. For methods that return a Future or Stream it requires thenAnswer((_) async => value), and it lists an ArgumentError on an async stub as the sign you used thenReturn.
Is it safe to run?
It edits your code and pubspec.yaml and runs build_runner and your tests. Use version control and read the diff before committing.
Which mock annotation does it use?
@GenerateNiceMocks. SKILL.md says to prefer it over @GenerateMocks to avoid missing-stub exceptions.
Information
updated Nov 2, 2026
- Repository
- dart-lang/skills
- Folder
skills/dart-generate-test-mocks
Sources
Docs, issue trackers and discussions this page is built from.
Show all 4Hide
- dart-generate-test-mocks SKILL.md · github.com
- dart-lang/skills README · github.com
- dart-generate-test-mocks on skills.sh · skills.sh
- dart-lang/skills · github.com