如何使用pipeline和jacoco獲取自動化測試程式碼覆蓋率
阿新 • • 發佈:2020-11-24
1下載jacoco,並上傳至伺服器:https://www.eclemma.org/jacoco/
2.應用服務tomcat的catalina.sh增加jacocoagent
#JAVA_OPTS="$JAVA_OPTS -javaagent:/Users/qiaojiafei/Documents/work/jacoco/jacoco-0.8.3/lib/jacocoagent.jar=includes=*,classdumpdir=classes,output=tcpserver,address=127.0.0.1,port=6300"
2.jenkins的pipeline配置
node { stage('Test') { echo 'This is a test step' checkout poll: false,scm: [$class: 'GitSCM',branches: [[name: '*/develop']],doGenerateSubmoduleConfigurations: false,extensions: [],submoduleCfg: [],userRemoteConfigs: [[credentialsId: 'bad9f924--4416-9f5e-',url: 'http://:8000/qiaojiafei/platform-qa.git']]] sh 'mvn clean test -DapiTest.xml -Dmaven.test.failure.ignore=true' } stage('rd code') { echo 'This is a test step' checkout poll: false,branches: [[name: '*/master']],url: 'http://:8000/qingzhuhotel/qingzhutool.git']]] sh 'mvn compile' } stage('DumpFromServer'){ echo 'This is a DumpFromServer step' sh label: '',script: 'mvn org.jacoco:jacoco-maven-plugin:0.8.3:dump -Djacoco.address=192.168.162.224 -Djacoco.port=6300' } stage('jacoco'){ jacoco() } }
結果展示
jacoco原理
官網介紹:
https://www.jacoco.org/jacoco/trunk/doc/implementation.html
參考:
https://testerhome.com/topics/5757
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。