mockito

Generates mocks, stubs methods, and verifies interactions in Dart and Flutter tests.

1|Updated Aug 14, 2026
One-click install
npx skills add https://github.com/sohampawar1866/zeromile-go --skill mockito-sohampawar1866
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mockito
Source: https://github.com/sohampawar1866/zeromile-go/tree/main/.agents/skills/mockito
Command: npx skills add https://github.com/sohampawar1866/zeromile-go --skill mockito-sohampawar1866

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires mockito, build_runner.

What problem does it solve? Writing unit tests in Dart and Flutter often requires isolating code from its dependencies, and doing this incorrectly leads to brittle tests, confusing stubbing errors, and over-mocked suites that are hard to maintain. ## Core Features & Use Cases - Mock Generation: Create mocks with @GenerateMocks or @GenerateNiceMocks and build_runner, following correct annotation and build.yaml conventions. - Stubbing & Verification: Stub return values, errors, and sequential responses with when/thenReturn, then verify call counts and arguments with verify, verifyNever, and untilCalled. - Argument Matching & Capture: Use any, argThat, captureAny, and captureThat to flexibly match and inspect arguments passed to mocked methods. - Use Case: When testing a repository class that depends on an HTTP client, generate a mock client, stub its responses, and verify the correct endpoints were called with the right headers. ## Quick Start Generate a Mockito mock for my ApiClient class, stub its fetch method to return test data, and verify it was called exactly once.

Frequently Asked Questions about mockito

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

FAQPage Schema
How do I generate mocks with Mockito in Dart?

Annotate a test file with @GenerateMocks([MyClass]) or @GenerateNiceMocks([MockSpec<MyClass>()]), then run dart run build_runner build. Only annotate files under test/ by default, or use a build.yaml to generate mocks elsewhere.

When should I use a mock vs a fake vs a real object in Dart tests?

Prefer real objects when practical, and use a Fake (extends Fake) when you need a lightweight custom implementation without interaction verification. Use a Mock only when you need to verify interactions or stub dynamic responses.

What is the difference between @GenerateMocks and @GenerateNiceMocks?

@GenerateMocks throws an error when an unstubbed method is called, while @GenerateNiceMocks returns a simple legal value for missing stubs. Use nice mocks to avoid stubbing every method in large tests.

How do I verify a mocked method was called in Mockito?

Use verify(mock.method()) to check it was called at least once, verify(mock.method()).called(2) for exact counts, and verifyNever for calls that should not happen. For async code, await untilCalled(mock.method()) to wait for the interaction.

Why does my Mockito stub throw a missing stub error?

Mocks generated with @GenerateMocks throw when a method is called without a matching stub. Stub the method with when(mock.method()).thenReturn(value) before use, or switch to @GenerateNiceMocks for automatic fallback values.

How do I capture arguments passed to a mocked method?

Use verify(mock.method(captureAny)).captured to retrieve all arguments the method received, with captured.last giving the most recent one. Use captureThat with a matcher for conditional capturing of specific arguments.