Cobertura + jenkins 单元测试代码覆盖率统计
1、新建一个maven工程,在src/main/java 下建一个CoverageTest.java 类
package test_junit;
public class CoverageTest {
public CoverageTest() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public static int testadd(int x, int y){
int c = 0;
if(x == 10){
c = x + y;
}else{
c = (x + y)*2;
}
return c;
}
}
2、在src/main/java 新建一个测试类JunitTest.java
package junit; import org.junit.Assert;
import org.junit.Test; import test_junit.CoverageTest; /**
* Created by 000284 on 2017/2/6.
*/
public class JunitTest {
@Test
public void testadd(){
int b = CoverageTest.testadd(5, 20);
Assert.assertEquals(b,50);
} }
3、pom.xml 文件
<?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> <groupId>testunit</groupId>
<artifactId>test_junit</artifactId>
<version>1.0-SNAPSHOT</version>
<profiles>
<!-- Jenkins by default defines a property BUILD_NUMBER which is used to enable the profile. -->
<profile>
<id>jenkins</id>
<activation>
<property>
<name>env.BUILD_NUMBER</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>xml</format>
</formats>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies> </project>
3、jenkins 安装插件cobertura
4、新建jenkins job
build >Goals and options 设置:clean cobertura:cobertura
Cobertura xml report pattern 设置: **/target/site/cobertura/coverage.xml
post setps 设置:Enable the "Publish Cobertura Coverage Report" publisher
5、构建job 查看 Coverage Report 就会显示覆盖率报表
Cobertura + jenkins 单元测试代码覆盖率统计的更多相关文章
- oracle存储过程代码覆盖率统计工具
目前针对于高级语言如C++,JAVA,C#等工程都有相关的代码覆盖率统计工具,但是对于oracle存储过程或者数据库sql等方面的项目,代码覆盖率统计和扫描工具相对较少. 因此针对这种情况,设计了代码 ...
- VS2015+NUnit+OpenCover 完成单元测试代码覆盖率测试
1.VS2015+NUnit+OpenCover 完成单元测试代码覆盖率测试 https://download.csdn.net/download/qq_39441918/10522539 2.*注意 ...
- MSTest/NUnit 单元测试 代码覆盖率试用 OpenCover 和ReportGenerator
VS自带是单元测试代码覆盖率(VS自带这个是最佳选择)需要企业版才有.很蛋疼...... 1.下载安装OpenCover 和ReportGenerator. 关于这2个是干啥的百度下.简单说就是可以分 ...
- Python 代码覆盖率统计工具 coverage.py
coverage.py是一个用来统计python程序代码覆盖率的工具.它使用起来非常简单,并且支持最终生成界面友好的html报告.在最新版本中,还提供了分支覆盖的功能. 官方网站: http://ne ...
- iOS自动化探索(十)代码覆盖率统计
iOS APP代码覆盖率统计 今年Q3季度领导给加了个任务要做前后端代码覆盖率统计, 鉴于对iOS代码代码比较熟就选择先从iOS端入手,折腾一整天后终于初步把流程跑通了记录如下 覆盖率监测的原理 Xc ...
- Android自动化测试探索(五)代码覆盖率统计
Android 代码覆盖率统计 本周开始准备统计Android自动化用例的代码覆盖率,将最终使用的方法记录下来. 覆盖率监测的原理 覆盖率监测的原理跟iOS上的原理差不多,大致的思路参考下吧, iOS ...
- 使用GCOV进行代码覆盖率统计
GCOV是随GCC一起发布的用于代码覆盖率统计的工具,一般配合其图形化工具LCOV一起使用. 一.安装 GCOV不需要单独安装,LCOV下载后执行sudo make install即可完成安装. 二. ...
- Android自动化测试探索(七)代码覆盖率统计
之前在 https://www.cnblogs.com/zhouxihi/p/11453738.html 这篇写了一种统计Android覆盖率的方式 但是对于一些比较复杂或者代码结构不够规范的项目,有 ...
- Python 测试代码覆盖率统计工具 coverage.py
安装 您可以通常的方式安装coverage.py.最简单的方法是使用pip: $ pip install coverage 要安装预发布版本,您需要指定--pre: $ pip install --p ...
随机推荐
- servlet匹配路径时/和/*的区别(转)
本文转自https://blog.csdn.net/rongxiang111/article/details/53008829 一.<url-pattern>/</url-patte ...
- js 实现纯前端将数据导出excel
通过将json遍历进行字符串拼接,将字符串输出到csv文件,输出的文件不会再是html类型的文件而是真正的csv文件,代码如下 <html> <head> <p styl ...
- 创建带Mipmap的osg::Image
我们常用osgDB::readImage或者osg::Image::allocateImage()方式创建Image对象, 跟深一步的带Mipmap的Image怎样创建呢? 偶然在分析osgParti ...
- .net非托管资源的回收
释放未托管的资源有两种方法 1.析构函数 2.实现System.IDisposable接口 一.析构函数 构造函数可以指定必须在创建类的实例时进行的某些操作,在垃圾收集器删除对象时,也可以调用析构函数 ...
- 汉字的unicode码范围是多少?
unicode码的分布情况,够清楚了吧!不仅汉字,什么都有了! ******************************************************* 0000.. ...
- HTTP客户端都应该支持的五个特性
在我看来,HTTP客户端必须要支持如下五个特性. 缓存 最后修改时间的检查 ETags 压缩 重定向 缓存返回的头如下: Cache-Control: max-age=, public Expires ...
- [Node.js] Level 6. Socket.io
6.2 Setting Up socket.io Server-Side So far we've created an Express server. Now we want to start bu ...
- Visual Studio 2013 Update2
下载: http://download.microsoft.com/download/6/7/8/6783FB22-F77D-45C5-B989-090ED3E49C7C/vs2013.2.iso
- 用CSS下划线距离
但在我在CSS中新加了TEXT-DECORATION: underline; 后发现下划线离文本太近了,很难看. 代码一: a { text-decoration: none; background: ...
- (回溯法)数组中和为S的N个数
Given a list of numbers, find the number of tuples of size N that add to S. for example in the list ...