Description
Previous articles have described how to use Apacheant to execute the Jacoco tool, and here's how to use MAVEN to use the Jacoco tool.
1. First create a new MAVEN project as shown in the figure:
2:helloworld
Create a new test class Helloworld,code as shown in the figure:
3:helloworldtest
Create a new test class HelloWorld Test,code as shown in the figure:
4: Edit Pom.xml file Edit Pom.xml file, add Dependency Pack and Jacoco configuration, file as follows: &NBSP;&NB Sp [java] View plain copy <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/xsd/maven-4.0.0.xsd "> <modelversion>4.0.0</modelversion > <groupId>com.test.jacoco</groupId> < artifactid>testjacoco</artifactid> <version>0.0.1-snapshot</version > <name>JaCoCo Examples</name> <properties> <project.build.sourceencoding >UTF-8</project.build.sourceEncoding> <project.reporting.outputencoding>utf-8</project.reporting.outputencoding> <!-- Sonar --> <sonar.java.coveragePlugin> jacoco</sonar.java.coverageplugin> <sonar.dynamicAnalysis> reusereports</sonar.dynamicanalysis> <!-- The Destination file for the code coverage report has to be set to the same value in the parent pom and in each module pom. Then JaCoCo will add up information in the same report, so that, it will give the cross-module code coverage. --> <sonar.jacoco.itreportpath>${project.basedir}/target/jacoco.exec</ sonar.jacoco.itreportpath> <sonar.language>java</sonar.language > </properties> <dependencies> <!-- <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1 </version> <scope>test</scope> </dependency> --> <dependency> <groupId>junit</groupId> <artifactid>junit</artifactid> <version>4.11</version> <scope>test</scope> </dependency> </ dependencies> <build> < pluginmanagement> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.5.3.201107060350</version> </plugin> </ Plugins> </pluginManagement> < plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <configuration> <includes>com.*</includes> </configuration> <executions> <execution> <id>pre-test</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>post-test</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </ execution> </executions> </plugin> <plugin> <groupid>org.apache.maven.plugins</ groupid> <artifactid>maven-compiler-plugin </artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> </project>
5: Packaging test
As shown in the figure:
6: Implementation results of the execution results:
At this point, based on the use of Maven Jacoco, integrated Jenkins and Sonar please refer to the "Jacoco coverage tool use";