Generate Mockito mocks for Dart tests with build_runner
Define and generate mock objects for external dependencies with package:mockito and build_runner — @GenerateNiceMocks, stubbing with when/thenAnswer, verifying interactions, and the mock creation workflow
- What
- Define and generate mock objects for external dependencies with package:mockito and build_runner — @GenerateNiceMocks, stubbing with when/thenAnswer, verifying interactions, and the mock creation workflow
- Cost
- Free
- Needs
- the Dart SDK installed and a Dart project with classes designed for dependency injection (constructor-injected services) — the skill is guidance the agent follows, not software to install
- Install
- Copy the installer prompt below into your Muse — your agent does the rest.
Curated by Skill Harbor — @flutter's skill for generating Mockito mocks in Dart tests with `build_runner`: design classes for testability (inject external services through constructors, represent URLs as `Uri.parse()`), configure `pubspec.yaml` (`dart pub add dev:test dev:mockito dev:build_runner`), annotate the test file with `@GenerateNiceMocks([MockSpec<Dependency>()])` (preferred over `@GenerateMocks` to avoid missing-stub exceptions), import the generated `.mocks.dart` file, run `dart run build_runner build`. Stubbing rules: `when(mock.method()).thenReturn(value)` for sync methods, but **always** `thenAnswer((_) async => value)` for methods returning Future or Stream — never `thenReturn` on async. Verify interactions with `verify(mock.method()).called(n)` and argument matchers (`any`, `anyNamed`, `captureAny`). Includes a 10-step creating-and-running workflow with checklist and a feedback loop for the classic failures (unexpected-null mock errors → use `@GenerateNiceMocks`; async `ArgumentError` → switch to `thenAnswer`; build_runner failures → check the `.mocks.dart` import matches the file name exactly). Honest caveats: methodology only — you need the Dart SDK and classes designed with constructor injection; the companion skill dart-add-unit-test (same repo) covers the test-writing side; note a similar listing `dart-lang-skills-dart-generate-test-mocks` from a different repo also exists on Skill Harbor — this one is the flutter/agent-plugins version. BSD-3-Clause licensed. Skill Harbor never reviews the code, review it yourself before use. Discovered via skills.sh.
Version:
Install
Prerequisites: the Dart SDK installed and a Dart project with classes designed for dependency injection (constructor-injected services) — the skill is guidance the agent follows, not software to install Install "Generate Mockito mocks for Dart tests with build_runner" for me. It teaches my agent @flutter's Mockito workflow: design for testability (constructor injection, Uri.parse for URLs); add dev:test, dev:mockito, dev:build_runner to pubspec; annotate with @GenerateNiceMocks([MockSpec<Dependency>()]); import the generated .mocks.dart file; run dart run build_runner build; stub with when()/thenReturn for sync and thenAnswer for async (never thenReturn on Future/Stream); verify interactions with verify().called(n) and argument matchers; follow the 10-step checklist and the failure feedback loop. BSD-3-Clause licensed. Repository: https://github.com/flutter/agent-plugins/blob/main/skills/dart-generate-test-mocks/SKILL.md 1. Fetch the SKILL.md file (and any helper files) from the repository path into a temporary folder and summarize what it does in one or two sentences. 2. Safety check: review the SKILL.md and scripts for anything suspicious (unexpected network calls, shell commands, credential harvesting). This repo should contain zero secrets in code, credentials only via the secure vault, allowed hosts declared in the SKILL.md. Verify that holds here; STOP on any red flag and tell me. 3. Install it as a skill: copy SKILL.md and its helper files into the agent's skills directory, in a folder named "dart-generate-test-mocks". 4. Verify with no network calls: frontmatter valid, files in place. 5. Report what was installed, where, and what I still need to do myself (e.g. point the agent at the classes to mock and the external dependencies to isolate; install the companion dart-add-unit-test skill from the same repo for the test-writing side). GitHub is optional: if I have a GitHub account or the gh CLI, you may use it; otherwise public access is fine. Never require it unless it's in the prerequisites above. Rules: don't touch anything outside the temp folder and the install target. If anything looks off, stop and ask me.
Questions
How do I install a build?
Every product page includes a copy-paste install prompt. Paste it into your Muse and it sets the build up for you — no manual configuration.
Where does my money go?
Straight to the seller. Skill Harbor never processes payments: checkout happens on the seller’s own page, usually Stripe.
What does the ✓ next to a creator’s name mean?
It means we confirmed the identity of the person behind the listing. It says nothing about the code itself — always check a build before installing it.