maven项目使用jacoco插件检测代码覆盖率详细配置

使用maven构建项目(java项目或者web项目都可以)

jacoco插件的配置参考官方网址:http://www.eclemma.org/jacoco/trunk/doc/maven.html

(1)配置jacoco的依赖jar包

<dependency><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.7.8</version>
</dependency>

 

(2)配置jacoco的插件,以及相关的goal

 <plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.7.8</version>
    <!--这里的execution ,每一个执行的goal,对应的id必须是唯一的--><executions><execution><id>prepare-agent</id><goals><goal>prepare-agent</goal></goals></execution>
        <!--这个check:对代码进行检测,控制项目构建成功还是失败--><execution><id>check</id><goals><goal>check</goal></goals></execution>
        <!--这个report:对代码进行检测,然后生成index.html在 target/site/index.html中可以查看检测的详细结果--><execution><id>report</id><phase>prepare-package</phase><goals><goal>report</goal></goals></execution></executions></plugin>

 

(3)配置代码检查的约束 rules

<!-- Configuration 里面写配置信息 --><configuration><!-- rules里面指定覆盖规则 --><rules><rule implementation="org.jacoco.maven.RuleConfiguration"><element>BUNDLE</element><limits><!-- 指定方法覆盖到80% --><limit implementation="org.jacoco.report.check.Limit"><counter>METHOD</counter><value>COVEREDRATIO</value><minimum>0.80</minimum></limit><!-- 指定指令覆盖到80% --><limit implementation="org.jacoco.report.check.Limit"><counter>INSTRUCTION</counter><value>COVEREDRATIO</value><minimum>0.80</minimum></limit><!-- 指定行覆盖到80% --><limit implementation="org.jacoco.report.check.Limit"><counter>LINE</counter><value>COVEREDRATIO</value><minimum>0.80</minimum></limit><!-- 指定类覆盖到100%,不能遗失任何类 --><limit implementation="org.jacoco.report.check.Limit"><counter>CLASS</counter><value>MISSEDCOUNT</value><maximum>0</maximum></limit></limits></rule></rules>
</configuration>

 

(4)完整的pom.xml的配置如下

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>cn.demo</groupId><artifactId>answers</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>answers</name><url>http://maven.apache.org</url><build><finalName>answers</finalName><plugins><plugin><inherited>true</inherited><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>${compiler.source}</source><target>${compiler.target}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin>

        <!--检查代码覆盖率的插件配置--><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.7.8</version><executions><execution><id>prepare-agent</id><goals><goal>prepare-agent</goal></goals></execution><execution><id>check</id><goals><goal>check</goal></goals></execution><execution><id>report</id><phase>prepare-package</phase><goals><goal>report</goal></goals></execution></executions><!-- Configuration 里面写配置信息 --><configuration><!-- rules里面指定覆盖规则 --><rules><rule implementation="org.jacoco.maven.RuleConfiguration"><element>BUNDLE</element><limits><!-- 指定方法覆盖到80% --><limit implementation="org.jacoco.report.check.Limit"><counter>METHOD</counter><value>COVEREDRATIO</value><minimum>0.80</minimum></limit><!-- 指定指令覆盖到80% --><limit implementation="org.jacoco.report.check.Limit"><counter>INSTRUCTION</counter><value>COVEREDRATIO</value><minimum>0.80</minimum></limit><!-- 指定行覆盖到80% --><limit implementation="org.jacoco.report.check.Limit"><counter>LINE</counter><value>COVEREDRATIO</value><minimum>0.80</minimum></limit><!-- 指定类覆盖到100%,不能遗失任何类 --><limit implementation="org.jacoco.report.check.Limit"><counter>CLASS</counter><value>MISSEDCOUNT</value><maximum>0</maximum></limit></limits></rule></rules></configuration></plugin></plugins></build><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><compiler.source>1.7</compiler.source><compiler.target>1.7</compiler.target><junit.version>4.12</junit.version></properties><dependencies><dependency><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.7.8</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>${junit.version}</version><scope>test</scope></dependency></dependencies> </project>

 

转载于:https://www.cnblogs.com/DFX339/p/8392019.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/453551.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

JAVA如何取得空list成员类型_String 类型的List作为一个成员变量保存,保存成功后取对象时报空指针...

异常&#xff1a;Caused by: java.lang.NullPointerException at org.litepal.crud.DataHandler.setToModelByReflection(DataHandler.java:1341) at org.litepal.crud.DataHandler.setGenericValueToModel(DataHandler.java:787) at org.litepal.crud.DataHandler.query(DataH…

C语言:几种字符输入函数的区别

几种字符输入函数的区别&#xff1a; 1、getche()函数:用于从键盘读入一个字符并显示&#xff0c;然后直接执行下一条语 句。2、getch()函数:用于从键盘中读入一个字符&#xff0c;但不显示在屏幕上&#xff0c;然后执行下一条语句。3、getchar()函数&#xff1a;用于从键盘读…

VCG Mesh刚性旋转(变换矩阵)

文章目录 一、简介二、实现代码三、实现效果参考资料一、简介 旋转矩阵如果从线性空间的角度来看,它类似于一个投影过程。假设坐标 P ( x 1 , y 1 , z 1 ) P(x_1,y_1,z_1)

薪水增长多少,新机会才值得考虑?

薪水增长多少,新机会才值得考虑? 阴历年马上就要来到&#xff0c;猪年正在向我们招手。相信有些朋友年后考虑新的要作机会&#xff0c;年终奖和第13个薪水已到手&#xff0c;是考虑一下离开这个让自己不“爽”公司的时候了&#xff0c;哈哈&#xff01; 但是&#xff0c;薪水…

ScaleAnimation动画

ScaleAnimation动画是用来进行缩放的动画&#xff0c;我在使用时刚开始有些不解的问题后来经过学习&#xff0c;有了一个更深的了解。先来看看源码&#xff0c;其实ScaleAnimation有四个构造函数&#xff0c;这里我只列出了其中的一个&#xff0c;因为另外的三个其实都只是这个…

Swift快速入门(一)第一个Swift程序

1. 本系列说明 本系列只是一个Swift快速入门的教程&#xff0c;并没有详尽的介绍Swift&#xff0c;Swift也并不是一个简单的编程语言&#xff0c;所以要想详尽的系统的学习Swift&#xff0c;本系列并不适合你&#xff0c;此系列只是让开发者可以快速的用Swift来进行开发。另外学…

java 判断数字变化增减_java String 强化操作 判断数字 字符串转阿拉伯数字,相似度等等...

importjava.io.BufferedReader;importjava.io.StringReader;importjava.util.ArrayList;importjava.util.List;importjava.util.regex.Matcher;importjava.util.regex.Pattern;/***author*/public classStrings {/*** 全角转半角**paramsbc 全角字符*returnString*/public stat…

[CareerCup] 4.7 Lowest Common Ancestor of a Binary Search Tree 二叉树的最小共同父节点

4.7 Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree. LeetCode上的原题&#xff0c;请参见我之前的博客Lo…

让猎头雨天送伞--大话猎头

让猎头雨天送伞--大话猎头(1) Arthur毕业之后&#xff0c;在一同家公司的研发部工作了7年&#xff0c;从初级开发工程师一直做到项目经理&#xff0c;过手十几个大项目&#xff0c;现在带领8人的研发团队。猎头最近频频与他沟通&#xff0c;希望他考虑几个外企研发主管的机会…

android布局的一些知识

(一)android:layout_alignParentBottom 控制该组件是否与布局容器底端对齐android:layout_alignParentLeft 控制该组件是否与布局容器左边对齐android:layout_alignParentRight 控制该组件是否与布局容器右边对齐android:layout_alignParentTop 控制该组件是否与布局容器顶端对…

IE8兼容问题总结---trim()方法

1.IE8不支持,jquery的trim()去空格的方法 错误表现 : 会报错,对象不支持此属性或方法; 解决办法 : 使用正则匹配空格 例如 : /^\s|\s$/greplace(/^\s|\s$/g,"");转载于:https://www.cnblogs.com/lizhiwei8/p/8392589.html

java的流套接_java-使用流关闭套接字

我的以下问题非常简单.这是我的代码&#xff1a;public class Protocol implements Runnable {private SSLSocket socket null;private InputStream is null;private OutputStream os null;...public Protocol(Socket s) {socket (SSLSocket)s;is socket.getInputStream()…

简历撰写

没什么可写的项目&#xff0c;或者自己说不太清&#xff0c;效果也不明显的项目&#xff0c;就不要写简历上了转载于:https://www.cnblogs.com/brainstorm/p/7942669.html

如何真正做好项目管理?

项目要能顺利执行其实并不简单&#xff0c;如果又渉及多个单位合作&#xff0c;困难程度又大增。 从项目经理的工作日志片段&#xff0c;可以看出每个项目经理应该都有自已悲惨的故事&#xff0c;程度恐怕只有过之而无不及。项目经理到底应该有那些看家本领呢&#xff1f; …

日历视图的XML属性

日历视图的XML属性 : -- 设置样式 : android:dateTextAppearance, 设置日期文字显示样式; -- 设置首日 : android:firstDayOfWeek, 设置星期几是每周的第一天, 默认是周一; -- 选中颜色 : android:focusedMonthDateColor, 设置选中日期所在月份日期颜色; -- 最大日期 : android…

作业30-首页列表显示全部问答,完成问答详情页布局

首页列表显示全部问答&#xff1a;将数据库查询结果传递到前端页面 Question.query.all()前端页面循环显示整个列表。问答排序app.route(/) def index():context{questions:Question.order_by(creat_time).query.all()}return render_template("index.html",**contex…

java重置radiobutton的选项_求助:这道题显示radiobutton男女的功能和重置功能怎么做...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼package org.demo.app.gui; import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax…

PopupWindow和AlertDialog区别

1 第一个重要的区别是AlertDialog不能指定显示位置&#xff0c;只能默认显示在 屏幕最中间&#xff08;当然也可以通过设置WindowManager参数来改变位置&#xff09;。 而PopupWindow是可以指定显示位置的&#xff0c;随便哪个位置都可以&#xff0c;更加灵活。 2 AlertDia…

Scala学习之爬豆瓣电影

简单使用Scala和Jsoup对豆瓣电影进行爬虫&#xff0c;技术比較简单易学。写文章不易&#xff0c;欢迎大家採我的文章&#xff0c;以及给出实用的评论&#xff0c;当然大家也能够关注一下我的github&#xff1b;多谢。 1、爬虫前期准备 找好须要抓取的链接&#xff1a;https://m…

新兴的多媒体格式——MXF 文件格式分析 和简介

1. 新兴的多媒体格式 MXF格式已经被推出几年了&#xff0c; 从当初一个陌生的不为人们 重视的格式 逐渐获得了业内人士的认知和认可&#xff0c; 现如今正被广泛应用于广播电视 与后期制作领域&#xff0c; 且有不断扩大之势&#xff0c; 松下公司推出的基于PII卡的 无磁带式…