Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the jacoco plug-in of jenkins to quickly achieve statistical unit test coverage

Shulou Source: shulou.com Published: 2022-06-02 09:06:42 10月27日 Update

This article mainly explains "how to use jacoco plug-in jenkins to quickly achieve statistical unit test coverage", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "how to use jacoco plug-in jenkins to quickly achieve statistical unit test coverage"!

Install jenkinswget http://mirrors.jenkins.io/war-stable/2.176.4/jenkins.warjava-jar jenkins.war Reference

Installing Jenkins via Java

jenkins optional plug-in is empty solution or jenkins cannot be networked

Install git, maven, jacoco and other plugins

Git plugin and JaCoCo plugin required

Configure maven

Configuration Unit Test Task

Spring-petclinic is a classic spring boot project, which we also chose here for unit testing and test coverage statistics. The project address is https://github.com/spring-projects/spring-petclinic.

Select the New Item link in Jenkins

Enter the new task page as follows

Enter spring-petclinic-uttest, select "Build a maven project" and click the "OK" button

General tab

leave the default values

Source Code Management tab

Repository URL Enter github.com/spring-projects/spring-petclinic.git

Build Triggers tab

leave the default values

Pre Steps tab

Enter "clean verify" in the Goals and options text box.

Post-build Actions tab

Click the Add post-build-Actions drop-down box and select the Record JaCoCo coverage report entry

Keep the default options, click the Save button at the end

Perform unit test tasks to view unit test coverage

According to the network situation and whether this task is executed for the first time, this task may take a long time to execute, and it is easy to interrupt and report errors. This time, I am newly installed jenkins on Alibaba Cloud host. It has been executed 4 times in total before it succeeds, as shown in the figure below.

The dot Coverage Trend link shows JaCoCo Coverage Trend at the bottom right as shown below

Continue to click anywhere in the JaCoCo Coverage Trend area to display the unit test coverage report as shown below

summary

This article explains how to trigger unit test execution using jenkins and use jacoco plug-in to count unit test case coverage through a specific example.

At this point, I believe that everyone has a deeper understanding of "how to use jacoco plug-in jenkins to quickly achieve statistical unit test coverage," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Tests units coverage plug-ins statistics tasks selections projects input content buttons methods links learning configuration utility deeper success host location Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information macOS Redmi MySQL