jacoco应用在p2pservice的实践

本地操作步骤
构建工程及启动服务

$ gradle clean build

$ java -javaagent:/home/rmeng/Application/jacoco/lib/jacocoagent.jar=output=tcpserver -jar ./build/libs/p2p-service.jar

   NEW TERMINAL

$ java -jar /home/rmeng/Application/jacoco/lib/jacococli.jar dump --destfile ./build/jacoco.exec

$ java -jar /home/rmeng/Application/jacoco/lib/jacococli.jar report ./build/jacoco.exec --classfiles ./build/classes/java/main/ --html ./build/html --sourcefiles ./src/main/java/

TEST

$ ./update_openapi_client.sh

$ cd tests

$ rm -rf ./allurereport

$ pytest -s -q p2pService  --p2p_host=http://127.0.0.1:7600  --alluredir=./allurereport

正式启动服务

$ java -javaagent:/home/rmeng/Application/jacoco/lib/jacocoagent.jar=output=tcpserver -jar ./build/libs/p2p-service.jar --spring.config.location=yitu.yml &

$ java -javaagent:/home/rmeng/Application/jacoco/lib/jacocoagent.jar=output=tcpserver -jar ./build/libs/p2p-service.jar --spring.config.location=yitu2.yml &

$ java -javaagent:/home/rmeng/Application/jacoco/lib/jacocoagent.jar=output=tcpserver -jar ./build/libs/p2p-service.jar --spring.config.location=WXEG0091.yml &

jenkins上面的配置
配置要求:

jenkins需要安装jacoco plugin(CI团队已经安装)

需要源代码和classes文件

(1)配置jacoco安装包的位置:

jacoco
parameters {
    string(name: 'source_pack', defaultValue: 'testGeneric/camp101/p2p-service-source.tar.gz', description: 'source code包')
}

(2)下载及解压jacoco

jacoco
stage('prepare jacoco') {
    steps {
        script{
            echo "start prepare jacoco stage..."
            sh """
                rm -rf jacoco/
                mkdir jacoco
            """
            echo "start download jacoco_package..."
            artifactoryUtils.download( "testGeneric/camp101/p2p-service-source.tar.gz","jacoco/jacoco-0.8.4.tar.gz", "true","fp-rt-server")
            echo "download success"
            sh """
                cd jacoco/
                tar xf jacoco-0.8.4.tar.gz
            """
        }
        // TODO
        echo "jacoco is ready"
    }
}

(3)启动jar包并启动jacoco在线插桩服务

jacoco
stage('deploy') {
    steps {
        echo "start deploy..."
        script {
            sh """
                ...
                #../p2p_package/p2p_service/shared/java/bin/java -javaagent:.../jacoco/jacoco-0.8.4/lib/jacocoagent.jar=output=tcpserver -jar ../*.jar &
 
            """
        }
    }
}

(4)测试完成后收集jacoco报告

jacoco
stage('collect jacoco report') {
    steps {
        script {
            sh """
                java -jar ../jacoco/jacoco-0.8.4/lib/jacococli.jar dump --destfile **/**.exec
            """
           }
        jacoco()
        echo 'jacoco report has been collected.'
    }
}

(5)页面数据展示

com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}valuecom.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value

具体覆盖率及源代码染色展示

Why does the coverage report not show highlighted source code?
Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports:

Class files must be compiled with debug information to contain line numbers.
Source files must be properly supplied at report generation time. I.e. specified source folders must be the direct parent of the folders that define the Java packages.
Can I collect coverage information without stopping the JVM?
Yes, there are three possible ways: The JaCoCo agent can be configured for remote control via TCP/IP sockets. This allows to collect execution data at any point in time from a running JVM. The dump Ant task, the dump Maven goal and the command line interface can be used to request dumps. The remote control feature also allows you to reset execution data.

Alternatively the JaCoCo agent can be configured to expose some functionality via JMX (jmx=true). The bean org.jacoco:type=Runtime provides operations to dump and reset execution data at any point in time.

In addition JaCoCo provides a Java API to directly access the runtime within the JVM executing the tests.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值