Skip to content

Setting Up Test Coverage Management

What you'll learn

  • Generating the coverage command for your monorepo toolkit
  • Configuring per-package coverage thresholds
  • Excluding generated files and boilerplate from coverage
  • Enforcing coverage gates in CI/CD

Prerequisites

  • An existing Archipelago monorepo (see Monorepo Scaffolding)
  • A monorepo_toolkit already generated at devtools/

Step 1: Generate the Coverage Manager Command

bash
archipelago generate coverage_manager

You will be prompted for:

  • appNameMyApp (must match your monorepo app name)
  • isForMonorepotrue

Or use a config file:

json
{
  "appName": "MyApp",
  "isForMonorepo": true
}
bash
archipelago generate coverage_manager --config coverage_config.json

Step 2: Understand the Generated Structure

The brick adds the coverage command to your monorepo toolkit:

devtools/
└── lib/src/
    └── commands/
        └── coverage/
            ├── coverage_command.dart        # CLI entry point
            ├── coverage_collector.dart      # LCOV collection + merging
            ├── coverage_reporter.dart       # Terminal & HTML reporting
            ├── threshold_checker.dart       # Pass/fail evaluation
            └── config/
                └── coverage_config.yaml     # Thresholds and exclusions

Step 3: Run Coverage Analysis

Collect and report test coverage across all packages:

bash
# Run tests and collect coverage for all packages
dart run devtools coverage

# Run coverage for specific packages
dart run devtools coverage --packages auth_sdk_impl,payment_sdk_impl

# Generate HTML report
dart run devtools coverage --format html --output coverage_report/

Step 4: Configure Thresholds and Exclusions

Edit the coverage config to set per-package thresholds:

yaml
# devtools/lib/src/commands/coverage/config/coverage_config.yaml
global_threshold: 80

package_overrides:
  auth_sdk_impl: 90
  core_infrastructure: 70

exclude_patterns:
  - "**/*.g.dart"
  - "**/*.freezed.dart"
  - "**/di/**"
  - "**/generated/**"

Step 5: Enforce in CI

Add coverage gates to your GitHub Actions workflow:

yaml
- name: Run tests with coverage
  run: dart run devtools coverage --min-coverage 80

- name: Upload coverage report
  uses: actions/upload-artifact@v4
  with:
    name: coverage-report
    path: coverage_report/

Key Customization Points

CustomizationWhere to Change
Global coverage thresholdcoverage_config.yamlglobal_threshold
Per-package overridescoverage_config.yamlpackage_overrides
Exclude file patternscoverage_config.yamlexclude_patterns
Output format (text, HTML, JSON)--format flag
Combine with affected detection--affected-only flag with base branch

Next Steps

Built by Banua Coder