springboot2.1.3+jacoco检测代码覆盖率
关于 jacoco的介绍,不在本文中详细描述,简单点说,只是个代码覆盖率工具,想要了解具体的可以参考如下地址:
https://www.jianshu.com/p/639e51c76544
好了,闲话不多说,上代码,先看下pom文件
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.szl.demo</groupId>
<artifactId>szldemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>szldemo</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
<jacoco.version>0.8.3</jacoco.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins> <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
新建一个简单的service类,用于后面的测试,如下:
package com.szl.demo.szldemo.service;
public class Calculator {
public int add(int a, int b) {
return a + b;
}
public int sub(int a, int b) {
return a - b;
}
}
写个单元测试类,如下:
package com.szl.demo.szldemo.service; import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class)
@SpringBootTest
public class CalculatorTest {
private Calculator instance = new Calculator(); @Test
public void testAdd() {
int a = 10;
int b = 20;
int expected = 30;
Assert.assertEquals(expected, instance.add(a, b));
} @Test
public void testSub() {
int a = 10;
int b = 20;
int expected = -10;
Assert.assertEquals(expected, instance.sub(a, b));
}
}
让我们进入控制台输入命令,或使用eclipse工具也可以实现,如下图:


这样,我们就成功生成了jacoco report了,我们可以去target/site/目录下就可找到。

打开index.html,我们就可以查看想看的内容了。

OK, 记录结束,没什么含金量,只是个工具而已,有需要的朋友拿去学习。
springboot2.1.3+jacoco检测代码覆盖率的更多相关文章
- jenkins使用jacoco插件检测代码覆盖率(八)
代码覆盖率:类覆盖,方法覆盖,行覆盖,指令覆盖……(简而言之,就是判断有没有被执行) 覆盖率 = 已经执行的代码 / 总代码 (1)创建maven项目,配置pom.xml如下 pom.xml < ...
- maven项目使用jacoco插件检测代码覆盖率详细配置
使用maven构建项目(java项目或者web项目都可以) jacoco插件的配置参考官方网址:http://www.eclemma.org/jacoco/trunk/doc/maven.html ( ...
- jenkins+jacoco配置代码覆盖率
一.服务器端配置 1.在代码部署服务器中安装jacoco,用于手工/接口测试覆盖率监听收集 2a.正常情况下,可在服务器中代码部署模块下的default文件夹中,修改tomcat文件如下 其中,inc ...
- 关于执行findbugs,checkstyle,jacoco插件检测代码,GitHook的脚本编写
Git钩子的作用: (pre-commit ) 在用户执行 git commit -m "xxx" 命令之前,先执行pre-commit文件中的脚本命令 在pre-commit文件 ...
- maven项目添加findbugs,checkstyle,jacoco,assembly,maven-jar-plugin插件的配置
(1)名称解释(插件的作用) findbugs:检测代码的不明显的语法错误.例如:用了==去比较字符串,定义了没有用的变量-- checkstyle:检测代码的格式规范.例如:方法没有写注释,类的命名 ...
- jacoco统计自动化代码覆盖率
jacoco统计自动化代码覆盖率 1. 简介 1.1. 什么是Jacoco Jacoco是一个开源的代码覆盖率工具,可以嵌入到Ant .Maven中,并提供了EclEmma Eclipse插件,也可以 ...
- Android自动化测试探索(五)代码覆盖率统计
Android 代码覆盖率统计 本周开始准备统计Android自动化用例的代码覆盖率,将最终使用的方法记录下来. 覆盖率监测的原理 覆盖率监测的原理跟iOS上的原理差不多,大致的思路参考下吧, iOS ...
- 基于深度学习的安卓恶意应用检测----------android manfest.xml + run time opcode, use 深度置信网络(DBN)
基于深度学习的安卓恶意应用检测 from:http://www.xml-data.org/JSJYY/2017-6-1650.htm 苏志达, 祝跃飞, 刘龙 摘要: 针对传统安卓恶意程序检测 ...
- [转]配置sonar、jenkins进行持续审查
本文以CentOS操作系统为例介绍Sonar的安装配置,以及如何与Jenkins进行集成,通过pmd-cpd.checkstyle.findbugs等工具对代码进行持续审查. 一.安装配置sonar ...
随机推荐
- 2019 GDD breaking world‘s record of π
Day 2 1.breaking pi‘s world record with google cloud [concept] memory wall: Originally theorized in ...
- POJ 3624 Charm Bracelet(01背包模板题)
题目链接 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52318 Accepted: 21912 Descriptio ...
- 【bat】【windows】win10查看所有wifi密码
win10的可以,win7的好像不行 @echo off & setlocal EnableDelayedExpansion title 查看所有wifi和密码 for /f "us ...
- 图论 --- 三维空间bfs
<传送门> [题目大意] 给你一个三维的迷宫,让你计算从入口走到出口最少步数. [题目分析] 其实和二维迷宫还是一样的,还是用队列来做,由于BFS算法一般是不需要回溯的,所以我们就用不着还 ...
- springboot异步线程
前言 最近项目中出现了一个问题,发现自己的定时器任务在线上没有执行,但是在线下测试时却能执行,最后谷歌到了这篇文章SpringBoot踩坑日记-定时任务不定时了?; 本篇文章主要以自己在项目中遇到的问 ...
- c++11多线程记录4:死锁
简单示例 举个例子,桌上有一支笔和一张纸,小A和小B都要拿到纸笔写字 小A拿了笔,小B拿了纸,这时就形成了死锁(两人都不愿意让出纸笔). 其实只要稍加控制就可以避免这种情况:规定必须先拿到纸再能去尝试 ...
- C_局部变量&全局变量
2018-5-9 Writen By Stephen.Yu 一.定义 1. 局部变量:在函数中定义的变量 2. 全局变量:在所有函数体之外定义 定义(Definition):声明并分配内存;未分 ...
- [译] QUIC Wire Layout Specification - Frame Types and Formats | QUIC协议标准中文翻译(4) 帧类型和格式
欢迎访问我的个人网站获取更好的阅读排版体验: [译] QUIC Wire Layout Specification - Frame Types and Formats | QUIC协议标准中文翻译(4 ...
- 【LEETCODE】64、链表分类,medium&hard级别,题目:2,138,142,23
package y2019.Algorithm.LinkedList.medium; import y2019.Algorithm.LinkedList.ListNode; /** * @Projec ...
- Python中NumPy的使用一
NumPy简介: 一个用python实现的科学计算,包括:1.一个强大的N维数组对象Array:2.比较成熟的(广播)函数库:3.用于整合C/C++和Fortran代码的工具包:4.实用的线性代数.傅 ...