dart-collect-coverage
Implementing Dart and Flutter Test Coverage
Contents
- Testing Fundamentals
- Coverage Directives
- Workflow: Configuring and Generating Coverage Reports
- Workflow: Advanced Manual Coverage Collection
- Examples
Testing Fundamentals
Structure your test suites using the standard Dart testing paradigms. Use package:test for Dart projects and flutter_test for Flutter projects.
- Unit Tests: Verify individual functions, methods, or classes.
- Component/Widget Tests: Verify component behavior, layout, and interaction using mock objects (
package:mockito). - Integration Tests: Verify entire app flows on simulated or real devices.
Coverage Directives
Exclude specific lines, blocks, or entire files from coverage metrics using inline comments. Pass the --check-ignore flag during formatting to enforce these directives.
More from dart-lang/skills
dart-add-unit-test
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains correct and regression-free.
2.1Kdart-fix-runtime-errors
Uses get_runtime_errors and lsp to fetch an active stack trace, locate the failing line, apply a fix, and verify resolution via hot_reload.
2.1Kdart-run-static-analysis
Execute `dart analyze` to identify warnings and errors, and use `dart fix --apply` to automatically resolve mechanical lint issues. Use during development to ensure code quality and before committing changes.
2.1Kdart-use-pattern-matching
Use switch expressions and pattern matching where appropriate
2.1Kdart-resolve-package-conflicts
Workflow for fixing package version conflicts. Use this when `pub get` fails due to incompatible package versions.
2.1Kdart-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.
2.1K