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.pswp.cn/news/453551.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/453551.shtml
英文地址,請注明出處:http://en.pswp.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卡的 無磁帶式…