|
| 1 | +# Coverage Analysis Setup |
| 2 | + |
| 3 | +This document describes the code coverage analysis and reporting setup for FsMath. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The project uses [Coverlet](https://github.com/coverlet-coverage/coverlet) for code coverage collection and reporting. Coverage reports are generated automatically during CI/CD builds with detailed HTML reports available as artifacts and coverage summaries in pull requests. |
| 8 | + |
| 9 | +## Tools Used |
| 10 | + |
| 11 | +- **Coverlet**: .NET code coverage library |
| 12 | +- **ReportGenerator**: Tool for generating HTML/XML coverage reports |
| 13 | +- **GitHub Actions**: CI/CD automation with coverage integration |
| 14 | + |
| 15 | +## Local Development |
| 16 | + |
| 17 | +### Running Tests with Coverage |
| 18 | + |
| 19 | +```bash |
| 20 | +# Basic coverage collection |
| 21 | +./build.sh runtestswithcoverage # Linux/macOS |
| 22 | +./build.cmd runtestswithcoverage # Windows |
| 23 | + |
| 24 | +# Full coverage report generation |
| 25 | +./scripts/generate-coverage.sh # Linux/macOS |
| 26 | +./scripts/generate-coverage.ps1 # Windows |
| 27 | +``` |
| 28 | + |
| 29 | +### Coverage Configuration |
| 30 | + |
| 31 | +The coverage setup is configured through several files: |
| 32 | + |
| 33 | +- `coverlet.runsettings`: MSBuild test settings for coverage collection |
| 34 | +- `.coverletrc`: Coverlet-specific configuration for exclusions |
| 35 | +- Test project files include `coverlet.msbuild` and `coverlet.collector` packages |
| 36 | + |
| 37 | +### Exclusions |
| 38 | + |
| 39 | +The following items are excluded from coverage analysis: |
| 40 | +- Test assemblies and test-related code |
| 41 | +- Generated code (marked with attributes) |
| 42 | +- Program entry points |
| 43 | +- Obsolete code |
| 44 | + |
| 45 | +## CI/CD Integration |
| 46 | + |
| 47 | +### GitHub Actions Workflow |
| 48 | + |
| 49 | +The `build-and-test.yml` workflow includes: |
| 50 | + |
| 51 | +1. **Test Execution**: Runs tests with coverage collection using XPlat Code Coverage |
| 52 | +2. **Report Generation**: Creates HTML and Cobertura reports using ReportGenerator |
| 53 | +3. **PR Comments**: Adds coverage summary comments to pull requests |
| 54 | +4. **Artifact Storage**: Stores HTML coverage reports as build artifacts |
| 55 | + |
| 56 | +### Coverage Thresholds |
| 57 | + |
| 58 | +- **Warning threshold**: 60% coverage |
| 59 | +- **Good threshold**: 80% coverage |
| 60 | +- **CI doesn't fail** on coverage below thresholds (informational only) |
| 61 | + |
| 62 | +## Coverage Reports |
| 63 | + |
| 64 | +### Local Reports |
| 65 | + |
| 66 | +- **Location**: `TestResults/CoverageReport/` |
| 67 | +- **Format**: HTML (main), Cobertura XML, JSON summary |
| 68 | +- **View**: Open `TestResults/CoverageReport/index.html` in browser |
| 69 | + |
| 70 | +### GitHub Integration |
| 71 | + |
| 72 | +- **Coverage Badge**: Generated in pull request comments |
| 73 | +- **PR Integration**: Coverage changes shown in pull request comments |
| 74 | +- **Artifact Downloads**: Full HTML reports available from GitHub Actions |
| 75 | + |
| 76 | +## Troubleshooting |
| 77 | + |
| 78 | +### Common Issues |
| 79 | + |
| 80 | +1. **No coverage data**: Ensure tests are running and `coverlet.collector` is installed |
| 81 | +2. **Low coverage**: Check exclusions in `.coverletrc` and `coverlet.runsettings` |
| 82 | +3. **Report generation fails**: Verify ReportGenerator is installed globally |
| 83 | + |
| 84 | +### Debug Coverage Collection |
| 85 | + |
| 86 | +```bash |
| 87 | +# Run with verbose logging |
| 88 | +dotnet test --collect:"XPlat Code Coverage" --logger "console;verbosity=detailed" |
| 89 | + |
| 90 | +# Check for coverage files |
| 91 | +find TestResults -name "*.cobertura.xml" |
| 92 | +``` |
| 93 | + |
| 94 | +## Maintenance |
| 95 | + |
| 96 | +The coverage setup should be reviewed periodically to: |
| 97 | + |
| 98 | +- Update exclusion patterns as the codebase evolves |
| 99 | +- Adjust coverage thresholds based on project maturity |
| 100 | +- Update tool versions (Coverlet, ReportGenerator) |
| 101 | +- Review GitHub Actions workflow and coverage reporting |
0 commit comments