Skill

coverage-report

Generate test coverage reports with HTML visualization and threshold enforcement

From dotnet
Install
1
Run in your terminal
$
npx claudepluginhub melodic-software/claude-code-plugins --plugin dotnet
Tool Access

This skill is limited to using the following tools:

BashReadGlobGrepAskUserQuestion
Skill Content

/dotnet:coverage-report

Generate comprehensive test coverage reports with HTML visualization, threshold enforcement, and coverage gap analysis.

Arguments

Parse arguments from $ARGUMENTS:

FlagDescriptionDefault
--format <format>Output format (cobertura, opencover, html, all)html
--threshold <percent>Fail if line coverage below thresholdNone
--project <path>Target specific test projectAll test projects
--output <path>Output directory for reports./coverage
--openOpen HTML report in browserfalse
--historyInclude historical trends (if available)false

Prerequisites

This command requires coverage tools. If not installed, will prompt:

Coverage tools not found. Install now?

Required:
  - dotnet-coverage (collection)
  - reportgenerator (HTML reports)

Run: /dotnet:install-tool --tool coverage
Run: /dotnet:install-tool --tool reportgen --global

Workflow

Step 1: Check Tool Availability

# Check for coverage tools
dotnet tool list | grep -E "dotnet-coverage|reportgenerator"

# Check global tools
dotnet tool list --global | grep reportgenerator

If missing, offer to install via /dotnet:install-tool.

Step 2: Find Test Projects

# Find test projects by convention
find . -name "*.Tests.csproj" -o -name "*.Test.csproj" -o -name "*Tests.csproj"

# Or by reference to test frameworks
grep -l "Microsoft.NET.Test.Sdk" **/*.csproj

Step 3: Run Tests with Coverage

Using dotnet-coverage (recommended for .NET 6+):

dotnet-coverage collect \
  --output coverage.cobertura.xml \
  --output-format cobertura \
  dotnet test --no-build

Using coverlet (alternative):

dotnet test \
  --collect:"XPlat Code Coverage" \
  --results-directory ./coverage

Step 4: Generate HTML Report

reportgenerator \
  -reports:coverage.cobertura.xml \
  -targetdir:./coverage/html \
  -reporttypes:Html \
  -assemblyfilters:"-*.Tests;-*.Test" \
  -classfilters:"-*Migrations*"

Step 5: Analyze Coverage

Parse coverage report for metrics:

  • Line coverage percentage
  • Branch coverage percentage
  • Method coverage percentage
  • Uncovered lines by file

Step 6: Threshold Check

If --threshold specified:

Coverage threshold check:
  Required: 80%
  Actual: 72.5%

  Status: FAILED

  Files below threshold:
    - src/MyApp/Services/PaymentService.cs (45%)
    - src/MyApp/Handlers/OrderHandler.cs (52%)
    - src/MyApp/Controllers/ReportController.cs (61%)

Output Format

Summary Report:

Test Coverage Report

Generated: 2026-01-18 11:00:00 UTC
Test Projects: 3
Tests Run: 247 passed, 0 failed

═══════════════════════════════════════════════════════════════
                    COVERAGE SUMMARY
═══════════════════════════════════════════════════════════════

  Metric              Coverage    Target    Status
  ─────────────────────────────────────────────────
  Line Coverage       78.5%       80%       WARN
  Branch Coverage     65.2%       70%       WARN
  Method Coverage     85.3%       80%       PASS

═══════════════════════════════════════════════════════════════

Coverage by Project:
  Project                    Lines      Branches   Methods
  ─────────────────────────────────────────────────────────
  MyApp.Core                 92.1%      88.5%      95.0%
  MyApp.Api                  75.3%      62.1%      82.4%
  MyApp.Infrastructure       68.2%      55.0%      78.6%

Top Uncovered Files:
  File                                    Coverage  Uncovered
  ────────────────────────────────────────────────────────────
  Services/PaymentService.cs              45.2%     87 lines
  Handlers/OrderHandler.cs                52.1%     64 lines
  Controllers/ReportController.cs         61.8%     45 lines
  Repositories/AuditRepository.cs         64.5%     38 lines
  Services/NotificationService.cs         67.2%     31 lines

Coverage Gaps (uncovered code patterns):
  - Exception handlers: 23 catch blocks untested
  - Edge cases: 15 null checks untested
  - Error paths: 12 error branches untested

HTML Report: ./coverage/html/index.html

Detailed Per-File Report:

Coverage Details: src/MyApp/Services/PaymentService.cs

  Overall: 45.2% (78/172 lines covered)

  Covered Methods:
    ✓ ProcessPayment()         100% (15/15 lines)
    ✓ ValidateCard()           100% (12/12 lines)
    ✓ GetPaymentStatus()       95%  (19/20 lines)

  Partially Covered Methods:
    ~ RefundPayment()          42%  (8/19 lines)
    ~ HandleFailure()          35%  (7/20 lines)

  Uncovered Methods:
    ✗ RetryPayment()           0%   (0/25 lines)
    ✗ ProcessBatchPayments()   0%   (0/31 lines)
    ✗ HandleWebhook()          0%   (0/30 lines)

  Uncovered Line Ranges:
    Lines 145-169: RetryPayment() - retry logic
    Lines 180-210: ProcessBatchPayments() - batch processing
    Lines 220-249: HandleWebhook() - webhook handling

  Recommendations:
    1. Add tests for retry scenarios
    2. Add tests for batch payment edge cases
    3. Add tests for webhook validation

Threshold Failure:

COVERAGE THRESHOLD FAILED

  Required: 80% line coverage
  Actual: 72.5% line coverage
  Gap: 7.5%

  To reach 80% coverage, add tests for ~150 more lines

  Quick wins (highest impact):
    1. PaymentService.cs: +27 lines = +1.5%
    2. OrderHandler.cs: +24 lines = +1.3%
    3. ReportController.cs: +18 lines = +1.0%

  Exit code: 1 (threshold not met)

Report Formats

FormatDescriptionUse Case
coberturaXML formatCI/CD integration, Azure DevOps
opencoverXML formatSonarQube, older tools
htmlInteractive HTMLLocal review, PR reviews
lcovLCOV formatGitHub Actions, Codecov
allGenerate all formatsComprehensive reporting

Integration Examples

Azure DevOps:

- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Build.SourcesDirectory)/coverage/coverage.cobertura.xml'

GitHub Actions:

- name: Upload coverage to Codecov
  uses: codecov/codecov-action@v3
  with:
    files: ./coverage/coverage.cobertura.xml

SonarQube:

dotnet sonarscanner begin \
  /k:"project-key" \
  /d:sonar.cs.opencover.reportsPaths="coverage/coverage.opencover.xml"

Examples

# Generate HTML coverage report
/dotnet:coverage-report

# Generate report with threshold enforcement
/dotnet:coverage-report --threshold 80

# Generate Cobertura XML for CI
/dotnet:coverage-report --format cobertura

# Generate all formats
/dotnet:coverage-report --format all

# Target specific test project
/dotnet:coverage-report --project MyApp.Tests

# Open report in browser
/dotnet:coverage-report --open

# Custom output directory
/dotnet:coverage-report --output ./artifacts/coverage

Filtering

Exclude from coverage analysis:

  • Test projects (*.Tests, *.Test)
  • Generated code (Migrations, designer files)
  • Third-party code

Configure in reportgenerator call:

-assemblyfilters:"-*.Tests;-*.Test;-*.Migrations"
-classfilters:"-*Generated*;-*Designer*"

Historical Trends

If --history and previous reports exist:

Coverage Trend (last 5 runs):

  Date          Line%   Branch%   Change
  ──────────────────────────────────────
  2026-01-18    78.5%   65.2%     +2.1%
  2026-01-15    76.4%   63.8%     +1.5%
  2026-01-12    74.9%   62.1%     +0.8%
  2026-01-10    74.1%   61.5%     -0.5%
  2026-01-08    74.6%   62.0%     --

  Trend: Improving (+3.9% over 10 days)
Stats
Parent Repo Stars40
Parent Repo Forks6
Last CommitFeb 15, 2026