How to apply JACOCO to actual enterprise practice~Test it, only 6 points are needed

1. Download jacoco

Official website: https://www.jacoco.org/jacoco/index.html

picture

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    

[Updated] A complete collection of the most detailed practical tutorials on Python interface automation testing taught by Bilibili (the latest practical version)_bilibili_bilibili [Updated] A complete collection of the most detailed practical tutorials on Python interface automated testing taught by Bilibili (practical version) The latest version) has a total of 200 videos, including: 1. Why interface automation should be done for interface automation, 2. Overall view of request for interface automation, 3. Interface practice for interface automation, etc. For more exciting videos from UP master, please follow the UP account . icon-default.png?t=N7T8https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337

2. Copy the jar package

picture

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;

picture

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)

picture

 

Guess you like

Origin blog.csdn.net/m0_73409141/article/details/132740082