dart-generate-test-mocks

Generate Dart mock objects with mockito and build_runner.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/mordechai30/.agents --skill dart-generate-test-mocks-mordechai30
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dart-generate-test-mocks
Source: https://github.com/mordechai30/.agents/tree/main/skills/dart-generate-test-mocks
Command: npx skills add https://github.com/mordechai30/.agents --skill dart-generate-test-mocks-mordechai30

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the complexity of manually creating mock objects for external dependencies in Dart applications, ensuring your unit tests remain isolated and reliable.

Core Features & Use Cases

  • Automated Mock Generation: Leverages build_runner and mockito to generate mock classes for complex dependencies like HTTP clients or databases.
  • Testability Patterns: Provides guidance on dependency injection and structuring Dart code for easier testing.
  • Use Case: When testing an API service that relies on an http.Client, use this Skill to generate a mock 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 classes for the dependencies defined in your test file by running the build runner command.

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 mocks for Dart unit testing?

To generate mocks for Dart unit testing, you use the mockito package alongside build_runner. You need to annotate dependencies with @GenerateNiceMocks and run the build runner command to automatically create type-safe mock classes.

What is the best way to mock external dependencies like APIs in Dart?

Mocking external API dependencies in Dart is best handled by generating mock classes for objects like HTTP clients. This allows you to simulate successful responses and error states without executing actual network calls during tests.

How does build_runner work with mockito to create test stubs?

Build runner works with mockito by reading @GenerateNiceMocks annotations in your test files to produce type-safe test stubs. Running the build runner command automates the generation of these mock classes for your isolated testing needs.

Do I need dependency injection to use mockito for mocking in Dart?

Yes, you need dependency injection to effectively use mockito for mocking in Dart. Structuring your code with dependency injection allows the generated mock objects to replace external services seamlessly during isolated unit tests.

How do I configure pubspec.yaml for Dart mock generation?

To configure pubspec.yaml for Dart mock generation, you must add mockito and build_runner as dependencies. Proper configuration ensures the build runner command can successfully generate type-safe and reliable mock classes.

Why are my generated Dart mocks missing type safety?

Generated Dart mocks might lack type safety if @GenerateNiceMocks annotations are not properly applied. Using these annotations ensures type-safe and reliable test stubs are created when running the build runner command.