Azure Devops Pipeline: Code coverage Report for Spring boot using Jacoco

Deepan Kumar Manivannan
2 min readMar 28, 2021


Kent Beck on Unit Testing

From Code Complete — Steve McConnell

Minimise gap between defect insertion and defect detection

  • Unit Test
  • Assertions
  • Formal code inspection
  • Pair Programming
  • Single Stepping through debugging

All of it complements each other.

Code coverage metrics help the team to keep an eye on the part of code that is being tested and not being tested. So that team can take the necessary steps to keep it under the preferable threshold. Increases transparency and accountability.
Azure pipeline provides out of box tools to publish code coverage reports. It can be achieved by just adding a couple of lines in the azure pipeline YAML config.

Maven configuration

Maven goal to run the test

  • In spring boot project, add spring boot test starter.
  • Set the phase of Jacoco plugin to `Test` so that maven goal — `Test` runs the tests as well as the jacoco code coverage

Azure Pipeline configuration

  1. Task to run the tests — task: Maven@3
  2. Task to publish the test results — PublishTestResults@2
  3. Task to publish the code coverage — PublishCodeCoverageResults@1
# azure-pipelines.yml
- stage: Build
displayName: Build stage
- job: CodeCoverage
displayName: Code Coverage
vmImage: "ubuntu-16.04"
- task: Maven@3
displayName: "Maven Test"
mavenPomFile: "pom.xml"
goals: "test"
- task: PublishTestResults@2
displayName: "Publish test results"
testResultsFormat: "JUnit"
mergeTestResults: true # Optional
- task: PublishCodeCoverageResults@1
displayName: "Publish publish code coverage"
summaryFileLocation: $(System.DefaultWorkingDirectory)/target/site/jacoco/jacoco.xml
pathToSources: $(System.DefaultWorkingDirectory)/src/main/java/

All done, if you run the pipeline you could see the code coverage report generated and published.

Screen snippet of code coverage tab from the azure pipeline



Deepan Kumar Manivannan

“The future belongs to those who learn more skills and combine them in creative ways.” ― Robert Greene, Mastery