Concept
Jacoco:jacoco is an open source coverage tool that is designed to be Java-based, with a flexible approach that can be embedded in ant, Maven, as an Eclipse plug-in, using its javaagent technology to monitor Java programs, and more.
Insert Pile: Program Insertion pile, it is to ensure the original logic integrity of the test program on the basis of inserting some probes (also known as "detectors", which is essentially a code snippet for information acquisition, can be an assignment statement or a function call to collect coverage information), through the execution of the probe and throw out the program running characteristic data, Through the analysis of these data, we can obtain the control flow and data flow information of the program, and then obtain the dynamic information such as the logical coverage, so as to realize the test purpose method.
On-the-fly: The agent that starts instrumentation by specifying a specific jar file in the JVM through the-javaagent parameter, the agent determines whether to convert the modified class file before loading a class with class loader. Insert the statistics code into class, and test coverage analysis can be done during the JVM execution of the test code.
Offline mode: Before testing, the file is inserted into the pile, and then generated the pile of class or jar package, after testing the pile's class and jar package, will generate dynamic overwrite information to the file, finally unified the coverage information processing, and generate reports.
Injection method
There are several ways to compare features:
Instrumentation injection
BYTE code bytecode injection (the ASM technique used in byte code modifies the bytecode method, can modify the jar file, the class file bytecode file, injected through a probe probe, the program can be recorded after execution, it does not change the behavior of the original code)
On-the-fly Online mode
Offline offline mode
The startup types currently supported by Eclipse Eclemma plugin:
Local Java Application Java Program (with main)
ECLIPSE/RCP Application Desktop Application
Equinox OSGi Framework
JUnit Test Unit Tests
TestNG Test
JUnit Plug-in Test
JUnit RAP Test
Swtbot Test
Scala Application
Installation
Eclipse:help->eclipse marketplace-> Search Eclemma
Java Application Overlay Test
Click the button in the toolbar (you may need to run the code first). The test results are as follows:
Red: Test not covered
Yellow: Test Partial overlay (usually if and switch)
Green: test is covered
View test rate, Window->show view->other->java->coverage
Typically, coverage shows a single-time overlay test result, and if you want to see multiple merge results more often, click
View coverage in Project Explorer, Window->preferences->general->appearence->label decorations, check Java Code Coverage.
JUnit Test Overlay Tests
Right-click a file that needs to be tested, new->junit->junit test case, complete a test class. Select Test class to start the overlay test. Results
Generate Coverage reports
File->export->java->coverage report-> Select the test source and destination address to generate the report
Original address: http://blog.csdn.net/myfwjy/article/details/73603286
Jacoco + Eclipse Unit test coverage