dart-generate-test-mocks

Generate mockito mock classes for Dart dependencies using build_runner.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires test, mockito, build_runner.

What problem does it solve?

This Skill eliminates the manual overhead of creating mock objects for complex external dependencies, ensuring your unit tests remain clean, maintainable, and decoupled from real-world services like APIs or databases.

Core Features & Use Cases

  • Automated Mock Generation: Leverages build_runner and mockito to generate type-safe mock classes from your existing interfaces.
  • Dependency Injection Support: Provides a structured workflow for injecting dependencies into constructors to facilitate easier testing.
  • 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 classes for the specified dependencies in my current 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, use the build_runner and mockito packages to automatically create type-safe mock classes from your existing interfaces, allowing isolated testing without real-world service dependencies.

What is the best way to mock asynchronous service calls in Dart?

The best way to mock asynchronous service calls in Dart is by configuring mockito within your test files to generate mock HTTP clients, enabling you to simulate successful responses and error states without executing actual network requests.

Does mockito support dependency injection for isolated Dart tests?

Yes, mockito supports dependency injection for isolated Dart tests by providing a structured workflow to inject dependencies into constructors, ensuring your unit tests remain decoupled from real APIs or databases.

Why do I need build_runner to create mocks in Dart?

You need build_runner to create mocks in Dart because it automates the generation of type-safe mock classes from your existing interfaces, eliminating the manual overhead of writing mock objects for complex external dependencies.

When should I not use automated mock generation for Dart?

You should not use automated mock generation for Dart when your tests require integration with actual external services, as this approach enforces dependency injection patterns specifically to isolate classes from real APIs and databases.