LogoAwesome Skills
  • Search
  • Category
  • Tag
  • Blog
LogoAwesome Skills
LogoAwesome Skills

Discover Open-Source Agent Skills for AI Coding Assistants

Product

  • Search
  • Category
  • Tag
  • Blog

Resources

  • Claude Skill Docs
  • Antigravity Skills Docs

Tools

  • Claude Code
  • OpenCode
  • Cursor
  • Codex
  • Antigravity

Company

  • Privacy Policy
  • Terms of Service
  • Sitemap

©2026 Awesome Skills. All rights reserved.

Privacy PolicyTerms
Back to Skills

dart-generate-test-mocks

Define and generate mock objects for external dependencies using `package:mockito` and `build_runner`. Use when unit testing classes that depend on complex external services like APIs or databases.

256stars18forksUpdated 5/21/2026
Testing & QA#dart#unit-testing#code-generation#testing#mocking#dependency-injection

Security Assessment

Safe(100/100)
Security Score100/100

About dart-generate-test-mocks

The dart-generate-test-mocks skill provides a structured approach to defining and generating mock objects in Dart applications, leveraging the `package:mockito` and `build_runner` tools. This skill is designed to simplify the process of unit testing classes that depend on complex external services, such as APIs or databases. By automating mock generation and enforcing best practices for testable code structures, it addresses the common challenges developers face when isolating dependencies, reducing the risk of brittle tests and ensuring consistent verification of interactions with external services.

The skill enables several key capabilities for Dart developers. It encourages designing classes for dependency injection, using strict type representations (e.g., `Uri` for URLs) and clear interfaces for external interactions. Dependencies are managed through proper `pubspec.yaml` configuration, separating runtime and testing dependencies. The skill automates mock generation using `@GenerateNiceMocks` annotations and `build_runner`, ensuring reliable asynchronous handling and verification. It also provides structured guidance for stubbing and verifying mock behaviors, including handling `Future` and `Stream` methods correctly, and offers a step-by-step workflow for creating, running, and troubleshooting mocked tests.

This skill is particularly useful for Dart developers engaged in unit testing of service-oriented or data-driven applications. It is ideal for teams aiming to enforce consistent testing patterns, reduce manual mock implementation, and improve test reliability. Typical use cases include testing HTTP client interactions, database operations, or any external service integration, where isolating the system under test is critical. By following this skill, developers can produce maintainable, robust tests that facilitate early bug detection and confidence in code correctness.

FAQ

How do I generate mock classes for my Dart project?

You place the `@GenerateNiceMocks` annotation in your test file with a list of `MockSpec<Type>()` objects, then run `dart run build_runner build` to generate the mock files, which are imported using the `.mocks.dart` extension.

Can this skill handle asynchronous methods in my tests?

Yes. For methods returning `Future` or `Stream`, always use `thenAnswer((_) async => value)` instead of `thenReturn` to correctly stub asynchronous behavior.

Which Dart packages are required for using this skill?

You need runtime dependencies such as `package:http` for external services, and dev dependencies including `test`, `mockito`, and `build_runner` for testing and mock generation.

Is this compatible with all Dart classes?

It is compatible with classes designed for dependency injection and clear interface definitions. Complex external services must be isolated to allow replacement with mock objects during testing.

What should I do if build_runner encounters errors?

Run `dart test` or `dart run build_runner build`, review errors for missing stubs, argument mismatches, or syntax issues in generated files, and adjust the mock specifications or test code accordingly.

Install dart-generate-test-mocks

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill

Repository

dart-lang/skills

Related Skills

short-form-video

14

multi-asset-morning-briefing

7,907

content-strategy

2,901

doherty-threshold

2,901