Introduction to the simple use of Jcoco

Source: Internet
Author: User

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> &LT;DATAFILE&GT;${PROJECT.BUILD.DIRECTORY}/COVERAGE-REPORTS/JACOCO.EXEC&LT;/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> &lt                ;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.