Automating Build Process for Java-based Application with Azure DevOps | Code Coverage Testing and Outcome Publishing

Code Coverage Testing and Outcome Publishing

Question

You are automating the build process for a Java-based application by using Azure DevOps.

You need to add code coverage testing and publish the outcomes to the pipeline.

What should you use?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

C

Use Publish Code Coverage Results task in a build pipeline to publish code coverage results to Azure Pipelines or TFS, which were produced by a build in

Cobertura or JaCoCo format.

Incorrect Answers:

A: Bullseye Coverage is used for C++ code, and not for Java.

Note:

There are several versions of this question in the exam. The question has two possible correct answers:

-> Cobertura

-> JaCoCo

Other incorrect answer options you may see on the exam include the following:

-> Coverlet

-> NUnit

-> Coverage.py

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-code-coverage-results

To add code coverage testing and publish the outcomes to the pipeline, you can use JaCoCo.

JaCoCo (Java Code Coverage) is an open-source code coverage library for Java-based applications. It provides accurate and detailed coverage reports for Java code, including line coverage, branch coverage, and method coverage.

To use JaCoCo in Azure DevOps, you can add the JaCoCo plugin to your build pipeline. Here are the steps:

  1. Add the JaCoCo Maven plugin to your project's pom.xml file:
php
<build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.4</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
  1. In your Azure DevOps pipeline, add a Maven task to build your Java project:

    • Select the "Maven" task from the task catalog.
    • In the "Maven options" field, enter "clean verify".
    • In the "POM file" field, enter the path to your project's pom.xml file.
    • In the "Goals" field, enter "clean verify".
  2. Add a JaCoCo report task to your pipeline:

    • Select the "JaCoCo report" task from the task catalog.
    • In the "Class files directories" field, enter the path to your project's compiled Java classes.
    • In the "Source files directories" field, enter the path to your project's Java source code.
    • In the "Report directory" field, enter the path to the directory where you want the JaCoCo coverage report to be generated.
  3. Run the pipeline and view the JaCoCo coverage report:

    • Once the pipeline has finished running, click on the "JaCoCo report" task to view the coverage report.
    • The report will show the percentage of code coverage for your Java code, broken down by line, branch, and method coverage.

In conclusion, JaCoCo is the appropriate tool to use for adding code coverage testing and publishing the outcomes to the pipeline in Azure DevOps.