1. Download jacoco
Official website: https://www.jacoco.org/jacoco/index.html
If you want to learn automated testing, I recommend a set of videos to you. This video can be said to be the number one automated testing tutorial on the entire network played by Bilibili. The number of people online at the same time has reached 1,000, and there are also notes that can be collected and communicated with various channels. Master technical communication: 798478386
2. Copy the jar package
3. Start jacocoagent and monitor the project under test
java -javaagent:jacocoagent.jar=includes=*,output=tcpserver,port=6300,address=localhost,append=true -jar demo-0.0.1.jar
#demo-0.0.1.jar为被测项目jar包
4. cli package dump generates exec file (note that it must be tested after completion)
java -jar cli-0.8.7.jar dump --address 127.0.0.1 --port 6300 --destfile jacoco-demo.exec
# --address 127.0.0.1 --port 6300 指向jacocoagent启动IP和端口
# jacoco-demo.exec 为生成exec文件名
5. cli package exec generates report report
java -jar cli-0.8.7.jar report jacoco-demo.exec --classfiles D:\code\devops\SBD\target\classes --sourcefiles D:\code\devops\SBD\src\main\java --html html-report --xml report.xml --encoding=utf-8
#--sourcefiles 和 --classfiles 为本地被测项目源码和字节码路径
6. Coverage report
Click on the report file under index.html
jacoco coverage, Cov represents coverage
The table columns are: elements; number of uncovered bytecode lines; number of uncovered branches; cyclomatic complexity; rows; methods; classes;
Coverage ID:
Conditional coverage: red diamond: indicates no coverage; yellow diamond: indicates partial coverage; green diamond: indicates full coverage;
Row coverage: full coverage (green), uncovered (red), half covered (yellow), ignored (white)