Code coverage analysis
Implement code coverage analysis
Publishing coverage
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.cobertura.xml'The coverage formats are Cobertura and JaCoCo — distinct from the test result formats (JUnit, NUnit, VSTest, xUnit, CTest). Mixing the two families up is a reliable exam trap.
What coverage does and does not tell you
Coverage measures which lines executed while tests ran. It does not measure whether anything was asserted. A test suite that calls every method and asserts nothing can report very high coverage and catch no defects.
So treat coverage as a signal about untested regions, not as a quality score:
| Use | Sound? |
|---|---|
| Find files with no tests at all | Yes — highly informative |
| Detect coverage falling on changed code | Yes — the most actionable gate |
| Compare team performance by percentage | No — invites gaming |
| Mandate a single global percentage | Weak — legacy code drags it; the number gets lowered |
Gating on it
The useful gate is on coverage of the code this change touched, not on the repository-wide figure. It asks a question the author can act on, cannot be satisfied by writing tests elsewhere, and does not penalise a codebase for its history.
Primary sources