Java应用程序的测试覆盖率之设计与实现(二)-- jacoco agent

说在前面的话

要想获得测试覆盖率报告,第一步要做的是,采集覆盖率数据,并输入到tcp。

而本文便是介绍一种java应用程序部署下的推荐方式。

作为一种通用方案,首先不想对应用程序有所侵入,其次运维和管理方便。

正好,jacoco agent就是类似于pinpoint agent一样,都使用了javaagent技术。

在灰度部署、压力测试等都许多场景下,都适用于javaagent技术。

一、jacoco agent

java agent技术,对jar应用程序没有入侵。

其作用是采集覆盖率数据,建议采用tcpserver的方式往外部输出。

安装简单,启动脚本增加以下参数:

bash 复制代码
basepath=/opt
# 本机IP
LOCAL_IP=192.168.10.128
# 服务名称
service=

# java包名是com.tech.*
java -javaagent:${basepath}/jacocoagent.jar=includes=com.tech.*,output=tcpserver,address=${LOCAL_IP},port=9322,classdumpdir=${basepath}/${service}/classdumpdir/classes/  -jar xxx.jar

二、参数说明

1、includes

默认是* (all classes) , 填写的是项目的class文件所在包package,多个之间使用冒号隔开。

2、output

  • file: At VM termination execution data is written to the file specified in the destfile attribute.
  • tcpserver: The agent listens for incoming connections on the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
  • tcpclient: At startup the agent connects to the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
  • none: Do not produce any output.

填写的是tcpserver,支持远程读取覆盖率数据。而file是保存于本地目录。

3、host

tcp server地址

4、port

tcp server端口

5、classdumpdir

class文件所在目录

下图为本地启动的测试结果。

6、append

是否追加,默认是true,设置为false时,每次重新生成。

三、总结

bash 复制代码
> ss -anlp |grep 9122
tcp  LISTEN  0  1  [::ffff:192.168.80.148]:9122  [::]:*  users:(("java",pid=18901,fd=10))

接下来,我们就可以远程连接tcpserver,dump出覆盖率数据了。

相关推荐
一起养小猫2 小时前
LeetCode100天Day12-删除重复项与删除重复项II
java·数据结构·算法·leetcode
乘风归趣2 小时前
idea、maven问题
java·maven·intellij-idea
人道领域2 小时前
【零基础学java】(多线程)
java·开发语言
幽络源小助理2 小时前
springboot基于Java的教学辅助平台源码 – SpringBoot+Vue项目免费下载 | 幽络源
java·vue.js·spring boot
星辰烈龙2 小时前
黑马程序员JavaSE基础加强d6
java·开发语言
亓才孓2 小时前
JUnit--Before,After,Test标签
java·junit·log4j
susu10830189112 小时前
maven-3.9.12的conf配置settings.xml
xml·java·maven
oMcLin2 小时前
如何在Rocky Linux 8.5上部署并优化Jenkins流水线,支持跨平台CI/CD自动化与容器化构建?
linux·ci/cd·jenkins
一直都在5722 小时前
MyBatis入门:CRUD、参数处理与防 SQL 注入
java·sql·mybatis
weixin_399380692 小时前
TongWeb+TongDataGrid+TongHttpServer实现Session复制
java·tomcat