测试与安全

dart-generate-test-mocks

flutter/agent-plugins

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.

这个 Skill 和 dart-lang/skills/dart-generate-test-mocks 内容相同,那边的安装量更高,建议优先选用。

  • 1.5万 次安装
  • 3100 星标
  • 收录于

安装命令

npx skills add https://github.com/flutter/agent-plugins --skill dart-generate-test-mocks

SKILL.md

Testing and Mocking Dart Applications

Contents

Structuring Code for Testability

Design Dart classes to support dependency injection. Isolate complex external dependencies (like API clients or databases) so they can be replaced with mock objects during testing.

  • Inject external services (e.g., http.Client) through class constructors.
  • Represent URLs strictly as Uri objects using Uri.parse(string).
  • Utilize Dart's object-oriented features (classes, mixins) to define clear interfaces for external interactions.

Managing Dependencies

Configure the pubspec.yaml file with the necessary testing and code generation packages.

Testing and Mocking Dart Applications

Contents

Structuring Code for Testability

Design Dart classes to support dependency injection. Isolate complex external dependencies (like API clients or databases) so they can be replaced with mock objects during testing.

  • Inject external services (e.g., http.Client) through class constructors.
  • Represent URLs strictly as Uri objects using Uri.parse(string).
  • Utilize Dart's object-oriented features (classes, mixins) to define clear interfaces for external interactions.

Managing Dependencies

Configure the pubspec.yaml file with the necessary testing and code generation packages.