dart-generate-test-mocks

Generate type-safe mock objects for Dart dependencies using mockito and build_runner.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses the complexity of unit testing classes with external dependencies by automating the creation of mock objects, ensuring your tests remain isolated and reliable.

Core Features & Use Cases

  • Automated Mock Generation: Uses build_runner and mockito to generate type-safe mock classes for external dependencies.
  • Dependency Injection Support: Provides a structured workflow to refactor code for better testability through constructor injection.
  • Use Case: When testing a service that fetches data from a REST API, use this skill to generate a mock HTTP client, allowing you to simulate successful responses and error states without making actual network calls.

Quick Start

Use the dart-generate-test-mocks skill to generate mock objects for the http client dependency in my api service test file.

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 generate mock objects for Dart unit testing?

To generate mock objects for Dart unit testing, you configure mockito and build_runner in your pubspec.yaml, then execute build_runner to automatically produce type-safe mock implementations of your external dependencies.

What is the best way to isolate Dart classes from external API services in tests?

The best way to isolate Dart classes from external API services in tests is to use dependency injection and mock objects, allowing you to simulate successful responses and error states without making actual network calls.

Do I need build_runner to create type-safe mocks with mockito?

Yes, you need build_runner to create type-safe mocks with mockito, as it executes the code generation process required to produce the mock implementations for your Dart application's external dependencies.

How does dependency injection improve testability when mocking Dart services?

Dependency injection improves testability by providing a structured workflow to refactor code, allowing you to easily substitute complex external services like databases or REST APIs with generated mock objects during unit testing.

Why does my build_runner mock generation fail to isolate my Dart unit tests?

Mock generation fails to isolate unit tests if you have not properly configured pubspec.yaml or correctly refactored your classes for constructor injection, preventing build_runner from producing the necessary type-safe mock implementations.