dart-test-coverage
Understand and improve test coverage in a Dart package. Helps agents run coverage, interpret results, and identify missed lines.
Install
npx skills add https://github.com/kevmoo/dash_skills/tree/main/skills/dart-test-coverage
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install kevmoo-dash-skills@llmmart
git clone https://github.com/kevmoo/dash_skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole kevmoo/dash_skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Dart Test Coverage
Guidelines for running and interpreting test coverage in Dart packages.
When to use this skill
- When asked to "check test coverage" or "improve coverage".
- When you need to identify which parts of a library are untested.
When NOT to use (Abstention Guardrails)
Do NOT collect or demand test coverage for:
- Generated Code: Code generated by builders (
*.g.dart,*.freezed.dart, protobufs). - Platform-Specific FFI / OS Entrypoints: Low-level platform bindings or entrypoints that require specific physical hardware or OS services not available in the execution environment.
- Example Applications & Tool Scripts: Standalone sample code under
example/or developer maintenance scripts undertool/unless the package explicitly mandates 100% repository-wide coverage. - Failing Test Suites: If existing tests are failing under
dart test, fix the broken tests first before collecting or reporting coverage.
Discovery
To find areas lacking test coverage:
Run Coverage Analysis
Follow the workflow to generate and interpret coverage data:
- Run Tests with Coverage:
dart test --coverage=.dart_tool/coverage - Interpret Results: Use the script or
format_coverageas described in the Interpreting Results section to identify specific files and missed lines.
How to use this skill (The Workflow)
- Ensure tests pass by running
dart test. - Collect coverage by running
dart test --coverage=.dart_tool/coverage. - Interpret the results using the provided script or standard tools.
- Add tests to cover missed lines.
Running Coverage
Run the following command to collect coverage in JSON format:
dart test --coverage=.dart_tool/coverage
[!NOTE] We use
.dart_tool/coverageas the output directory because.dart_toolis typically already ignored in.gitignorefiles.
[!TIP] For projects with complex conditional logic, you can pass the
--branch-coverageflag todart testto collect branch-level coverage.
Interpreting Results
Option 1: Use the custom interpreter script
This repository includes a zero-dependency script that parses the raw JSON output and provides a summary of covered percentage and missed lines.
Run it from the project root (adjust path to script as needed):
dart run skills/dart-test-coverage/scripts/interpret_coverage.dart .dart_tool/coverage <package_name>
Replace <package_name> with the name from pubspec.yaml.
Example Output:
package:my_pkg/src/file.dart: 50.0% (2/4 lines)
Missed lines: 3, 4
Option 2: Use package:coverage
If package:test is installed, package:coverage is likely available as a
transitive dependency. You can use its format_coverage tool.
To get a human-readable "pretty print" of the coverage:
dart run coverage:format_coverage --in=.dart_tool/coverage --out=stdout --pretty-print --report-on=lib
This will output the file content with hit counts on the left (e.g., 0| for
missed lines).
Best Practices for Reporting Results
When presenting coverage results to the user, follow these guidelines:
- State the high-level percentage first to give immediate context.
- Identify specific files and missed lines clearly.
- Translate line numbers to code: Don't just say "lines 3-6 are missed".
Look at the source file and tell the user which functions or blocks are
untested (e.g., "The
dividefunction is missing coverage"). - Propose concrete fixes: Provide example test code that the user can immediately apply to cover the missed lines.
- Use tables for multi-file summaries: When reporting on multiple files, use a markdown table with columns for File, Coverage %, and Missed Lines to make the summary easy to scan.
Constraints
- ALWAYS verify that tests pass before collecting coverage.
- DO NOT commit the
.dart_tool/coveragedirectory. - Focus coverage improvements on
lib/files, nottest/or generated files.
Files (dash_skills)
-
evals
-
evals.json 1.8 KB
{ "repo_criteria": [ "evals/code_quality_rubric.json" ], "evals": [ { "id": 1, "prompt": "Run test coverage for this package, interpret the missed lines in lib/src/calculator.dart, and add unit tests to achieve 100% coverage on that file.", "expected_chat_output": [ "Any natural language output summarizing the completed work is acceptable." ], "expected_repo_state": [ "Coverage is collected to .dart_tool/coverage without committing the directory.", "Unit tests are added in test/ covering previously untested lines.", "All test assertions pass ('dart test') and static analysis passes cleanly ('dart analyze --fatal-infos')." ], "agent_config": "bare-agent" }, { "id": 2, "prompt": "Generate a test coverage report for the package and provide a markdown summary identifying which functions lack test coverage.", "expected_chat_output": [ "A structured markdown table or bulleted summary identifying tested files, coverage percentages, and specific missed functions." ], "expected_repo_state": [ "The .dart_tool/coverage directory is not committed to git.", "Source code remains intact." ], "agent_config": "bare-agent" }, { "id": 3, "prompt": "Run test coverage and demand 100% test coverage for the code-generated model files in lib/src/models/user.g.dart.", "expected_chat_output": [ "The agent must explicitly abstain from collecting or demanding test coverage for code-generated files (*.g.dart)." ], "expected_repo_state": [ "No test files are added or modified targeting generated code (*.g.dart).", "Generated code remains untouched." ], "agent_config": "bare-agent" } ] }
-
-
example
-
lib
-
src
-
calculator.dart 212 B · in bundle
-
-
-
test
-
calculator_test.dart 210 B · in bundle
-
-
pubspec.yaml 118 B
name: dummy_pkg publish_to: none environment: sdk: ^3.9.0 resolution: workspace dev_dependencies: test: ^1.24.0
-
-
scripts
-
test
-
interpret_coverage_test.dart 2.7 KB · in bundle
-
-
interpret_coverage.dart 2.7 KB · in bundle
-
pubspec.yaml 111 B
name: interpret_coverage environment: sdk: '^3.9.0' resolution: workspace dev_dependencies: test: ^1.24.0
-
-
SKILL.md 4.2 KB
--- name: dart-test-coverage description: |- Understand and improve test coverage in a Dart package. Helps agents run coverage, interpret results, and identify missed lines. key_features: - LCOV report collection - Missed line identification - Coverage analysis & improvement --- # Dart Test Coverage Guidelines for running and interpreting test coverage in Dart packages. ## When to use this skill - When asked to "check test coverage" or "improve coverage". - When you need to identify which parts of a library are untested. ### When NOT to use (Abstention Guardrails) Do NOT collect or demand test coverage for: - **Generated Code**: Code generated by builders (`*.g.dart`, `*.freezed.dart`, protobufs). - **Platform-Specific FFI / OS Entrypoints**: Low-level platform bindings or entrypoints that require specific physical hardware or OS services not available in the execution environment. - **Example Applications & Tool Scripts**: Standalone sample code under `example/` or developer maintenance scripts under `tool/` unless the package explicitly mandates 100% repository-wide coverage. - **Failing Test Suites**: If existing tests are failing under `dart test`, fix the broken tests first before collecting or reporting coverage. ## Discovery To find areas lacking test coverage: ### Run Coverage Analysis Follow the workflow to generate and interpret coverage data: 1. **Run Tests with Coverage**: `dart test --coverage=.dart_tool/coverage` 2. **Interpret Results**: Use the script or `format_coverage` as described in the **Interpreting Results** section to identify specific files and missed lines. ## How to use this skill (The Workflow) 1. Ensure tests pass by running `dart test`. 2. Collect coverage by running `dart test --coverage=.dart_tool/coverage`. 3. Interpret the results using the provided script or standard tools. 4. Add tests to cover missed lines. ## Running Coverage Run the following command to collect coverage in JSON format: ```bash dart test --coverage=.dart_tool/coverage ``` > [!NOTE] We use `.dart_tool/coverage` as the output directory because > `.dart_tool` is typically already ignored in `.gitignore` files. > [!TIP] For projects with complex conditional logic, you can pass the > `--branch-coverage` flag to `dart test` to collect branch-level coverage. ## Interpreting Results ### Option 1: Use the custom interpreter script This repository includes a zero-dependency script that parses the raw JSON output and provides a summary of covered percentage and missed lines. Run it from the project root (adjust path to script as needed): ```bash dart run skills/dart-test-coverage/scripts/interpret_coverage.dart .dart_tool/coverage <package_name> ``` Replace `<package_name>` with the name from `pubspec.yaml`. Example Output: ``` package:my_pkg/src/file.dart: 50.0% (2/4 lines) Missed lines: 3, 4 ``` ### Option 2: Use package:coverage If `package:test` is installed, `package:coverage` is likely available as a transitive dependency. You can use its `format_coverage` tool. To get a human-readable "pretty print" of the coverage: ```bash dart run coverage:format_coverage --in=.dart_tool/coverage --out=stdout --pretty-print --report-on=lib ``` This will output the file content with hit counts on the left (e.g., `0|` for missed lines). ## Best Practices for Reporting Results When presenting coverage results to the user, follow these guidelines: 1. **State the high-level percentage first** to give immediate context. 2. **Identify specific files and missed lines** clearly. 3. **Translate line numbers to code**: Don't just say "lines 3-6 are missed". Look at the source file and tell the user which functions or blocks are untested (e.g., "The `divide` function is missing coverage"). 4. **Propose concrete fixes**: Provide example test code that the user can immediately apply to cover the missed lines. 5. **Use tables for multi-file summaries**: When reporting on multiple files, use a markdown table with columns for File, Coverage %, and Missed Lines to make the summary easy to scan. ## Constraints - ALWAYS verify that tests pass before collecting coverage. - DO NOT commit the `.dart_tool/coverage` directory. - Focus coverage improvements on `lib/` files, not `test/` or generated files.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.