1.Jenkins安装插件Clover Plugin
2.修改配置文件
<1>.修改pom.xml
dependency部分
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.1</version> <scope>test</scope> <optional>true</optional> </dependency>
plugin部分
<plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>clover-maven-plugin</artifactId> <!-- maven-clover2-plugin before 4.1.1 --> <version>4.1.1</version> </plugin>
<2>.修改Jenkinsfile
//单元测试阶段 stage("unit-test") { when { expression { ENV =~ 'CI.*' } } steps { echo "自动化测试,单元测试" sh 'mvn clean clover:setup test clover:aggregate clover:clover' } //3.收集html测试报告 post { always { script { //allowEmptyResults: true允许空结果即没有测试报告输出,skipPublishingChecks: true跳过github发布检查 if (env.moudle_name == '.') { junit allowEmptyResults: true, skipPublishingChecks: true, testResults: "**/target/surefire-reports/*.xml" clover(cloverReportDir: 'target/site', cloverReportFileName: 'clover.xml', // optional, default is: method=70, conditional=80, statement=80 healthyTarget: [methodCoverage: 70, conditionalCoverage: 80, statementCoverage: 80], // optional, default is none unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50], // optional, default is none failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0] ) publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'target/site/clover', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: '']) } else { junit allowEmptyResults: true, skipPublishingChecks: true, testResults: "**/${params.moudle_name}/target/surefire-reports/*.xml" clover(cloverReportDir: '${params.moudle_name}/target', cloverReportFileName: 'clover.xml', // optional, default is: method=70, conditional=80, statement=80 healthyTarget: [methodCoverage: 70, conditionalCoverage: 80, statementCoverage: 80], // optional, default is none unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50], // optional, default is none failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0] ) publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: '${params.moudle_name}/target/site/clover', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: '']) } } } } }
标签:集成,clover,methodCoverage,conditionalCoverage,50,Jenkins,80,true From: https://www.cnblogs.com/xiaoxiaomuyuyu/p/16834677.html