mocktail
Skill669 starsChanged 3 months agoMITView on GitHub
Use when creating mocks, stubbing methods, verifying interactions, registering fallback values, or choosing between mocks, fakes, and real objects (Mocktail).
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- accessibilitySkill
- architecture-feature-firstSkill
- blocSkill
- code-reviewSkill
- dart-3-updatesSkill
- developing-genkit-dartSkill
- effective-dartSkill
- firebase-aiSkill
- firebase-analyticsSkill
- firebase-app-checkSkill
- firebase-authSkill
- firebase-cloud-firestoreSkill
- firebase-cloud-functionsSkill
- firebase-crashlyticsSkill
- firebase-databaseSkill
- firebase-data-connectSkill
- firebase-in-app-messagingSkill
- firebase-messagingSkill
- firebase-remote-configSkill
- firebase-storageSkill
- flutter-app-architectureSkill
- flutter-best-practicesSkill
- flutter-change-notifierSkill
- flutter-errorsSkill
- flutterfire-configureSkill
- flutter-pre-cachingSkill
- flutter-use-column-row-firstSkill
- generate-images-with-firebase-aiSkill
- inclusive-designSkill
- mockitoSkill
- patrol-e2e-testingSkill
- providerSkill
- revenuecat-testingSkill
- riverpodSkill
- testingSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 21
Never add @override methods or implementations to a class extending Mock.
- Very specific: line 22
Only use mocks if your test has verify assertions.
- Very specific: line 33
No code generation required — unlike Mockito, Mocktail uses noSuchMethod at runtime.
- Very specific: line 70
Always stub async methods (returning Future or Future<void>) with thenAnswer.
- Very specific: line 77
Always include all named parameters in both when and verify calls.
- Distinctive: line 86
If a method has default values for named parameters, Mocktail still expects them all to be matched.
- Very specific: line 111
Use any() for positional parameters when you don't care about the exact value.
- Very specific: line 112
Use captureThat() for conditional capturing.
- Very specific: line 113
When matching string output, be aware of what .toString() returns for the type.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mocktail Skill
This skill defines how to correctly use the mocktail package for mocking in Dart and Flutter tests.
1. Mock vs. Fake vs. Real Object
| Use | When |
| Real object | Prefer over mocks when practical. |
Fake (extends Fake) | Lightweight custom implementation; override only the methods you need. Prefer over mocks when you don't need interaction verification. |
Mock (extends Mock) | Only when you need to verify interactions (call counts, arguments) or stub dynamic responses. |
- Never add
@overridemethods or implementations to a class extendingMock. - Only use mocks if your test has
verifyassertions; otherwise prefer real or fake objects.
2. Creating Mocks
class MockMyService extends Mock implements MyService {}
class FakeMyEvent extends Fake implements MyEvent {}No code generation required — unlike Mockito, Mocktail uses noSuchMethod at runtime.
3. Registering Fallback Values
Register fallback values before using custom types with argument matchers. Do this in setUpAll or at the top of your test:
setUpAll(() {
registerFallbackValue(FakeMyEvent());
});- Required for non-nullable custom types used with
any(),captureAny(), orcaptureThat(). - Register fallback values for any custom type used with argument matchers.
4. Stubbing
final mock = MockMyService();
// Return a value
when(() => mock.fetchData()).thenReturn('result');
// Throw an error
when(() => mock.fetchData()).thenThrow(Exception('error'));
// Dynamic/async response
when(() => mock.fetchData()).thenAnswer((_) async => 'result');
// Future<void>
when(() => mock.doWork()).thenAnswer((_) async {});- Always stub async methods (returning
FutureorFuture<void>) withthenAnswer. - Stub every method you expect to be called, even if it's not the focus of your test.
5. Named Parameters
Always include all named parameters in both when and verify calls. Use any(named: 'paramName') for those you don't care about:
when(() => mock.fetch(
id: any(named: 'id'),
headers: any(named: 'headers'),
)).thenReturn(response);- If a method has default values for named parameters, Mocktail still expects them all to be matched.
6. Verification
verify(() => mock.fetchData()); // called at least once
verifyNever(() => mock.fetchData()); // never called
verify(() => mock.fetchData()).called(2); // called exactly twice7. Argument Matchers
// Any positional argument
when(() => mock.process(any())).thenReturn(true);
// Capture arguments for later assertions
final captured = verify(() => mock.process(captureAny())).captured;
print(captured.last);- Use
any()for positional parameters when you don't care about the exact value. - Use
captureThat()for conditional capturing. - When matching string output, be aware of what
.toString()returns for the type.
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

