dart-generate-test-mocks

Generate mocks for Dart unit tests using mockito and build_runner.

428|29|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/dart-lang/skills --skill dart-generate-test-mocks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dart-generate-test-mocks
Source: https://github.com/dart-lang/skills/tree/main/skills/dart-generate-test-mocks
Command: npx skills add https://github.com/dart-lang/skills --skill dart-generate-test-mocks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Generating and mocking external dependencies for reliable Dart unit tests, enabling isolated testing of components that interact with APIs, databases, or other services.

Core Features & Use Cases

  • Automatic mock generation with package:mockito and build_runner.
  • Easy testability through dependency injection and mock abstractions.
  • Use cases include API clients, HTTP services, and external integrations.

Quick Start

Create a new test and annotate dependencies with @GenerateNiceMocks, then run dart run build_runner build to generate the mocks.

Frequently Asked Questions about dart-generate-test-mocks

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

FAQPage Schema
How do I mock external dependencies for Dart unit tests?

To mock external dependencies for Dart unit tests, you can use the @GenerateNiceMocks annotation alongside package:mockito and build_runner. This setup generates mock classes for external integrations, enabling isolated testing of components that interact with APIs, databases, or other services.

How do I generate mocks using build_runner and mockito?

Generating mocks with build_runner and mockito requires annotating your test dependencies with @GenerateNiceMocks. After adding the annotations, simply run dart run build_runner build to automatically generate the required .mocks.dart file for your tests.

Does this mock generation approach work for Flutter API clients and HTTP services?

Yes, this mock generation approach works for Flutter API clients and HTTP services. It is specifically applicable to unit tests across Dart and Flutter projects, allowing you to mock external integrations and test components reliably in isolation.

Do I need dependency injection to use generated mocks in Dart?

Yes, you need dependency injection to use generated mocks effectively in Dart. Injecting mock abstractions into your components allows you to isolate the unit under test from external dependencies like API clients and database integrations during test execution.

What is the best way to isolate database integrations when testing Dart applications?

The best way to isolate database integrations when testing Dart applications is to abstract them behind interfaces and use @GenerateNiceMocks. By running build_runner, you generate mock implementations that simulate database responses without requiring a real database connection.