There are two ways to use Jcoco:
1. Using Eclipse plugin directly, disadvantage: Cannot generate report, only see effect on eclipse
2. Using the Maven plugin
1, the use of online installation method:
Diagram steps:
Success Flag:
Test: (using the same method as run as)
Result analysis: Green refers to the place where the test is performed, and the red is not the place to execute it.
You can also view the coverage of each method in each class:
2. Use Maven to get the same effect as the front
Step: Add the Jcoco plug-in to the Pom and specify the report's Build path
<!--Jacoco Plugin--<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.6.4.201312101107</version > <executions> <execution> <!--in maven Initiali In the ze phase, the Jacoco runtime agent is passed as a parameter of the VM to the program being tested for monitoring calls in the JVM. -<id>default-prepare-agent</id> <goals> <goal>prepare-agent</go al> </goals> <configuration> <d Estfile>${project.build.directory}/coverage-reports/jacoco.exec</destFile> <propertyName>surefireArgLine</propertyName> </configuration> </execution> <!--The program that performs the report test during the verify phase of the program. The file input is perpare-set or Default jacoco.exec in the agent stage. The parameters includes and excludes can be used to select the classes that are filtered in the report. -<execution> <id>default-report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> <configura Tion> <DATAFILE>${PROJECT.BUILD.DIRECTORY}/COVERAGE-REPORTS/JACOCO.EXEC</DATAFILE&G T <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory> </con figuration> </execution> </executions> </plugin> <!--use maven-surefire-plugin to perform unit tests. Assign the Surefireargline to the Argline parameter to ensure that the Jacoco agent is running when the test is executed. -<plugin> <groupId>org.apache.maven.plugins</groupId> < ;artifactid>maven-surefire-plugin</artifactid> <version>2.16</version> <configuration> <argLine>${surefireArgLine}</argLine> </configurati On> </plugin>
Using:Run as, MAVEN test (maven automatically downloads the corresponding plugin and generates the corresponding report)
The effect of opening is the same as with the Eclipse plugin.
Have a research partner to exchange experience Ah, just contact is not very likely to use, THX
Introduction to the simple use of Jcoco