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 就会显示覆盖率报表

最新文章

  1. List [][]
  2. highlight高亮风格
  3. 使用jQuery解析JSON数据
  4. datatables增删改查的实现
  5. Android经典完美退出方法
  6. Sigmaplot激活码获取地址
  7. 16 SQL Tuning Overview
  8. Web Service和WCF的到底有什么区别
  9. JavaWeb学习总结(三十五)——使用JDBC处理Oracle大数据
  10. ios真机调试详细步骤
  11. Linq101-Partitioning
  12. ThinkPhp3.2 无法加载模块:Index
  13. J2EE基础总结(4)——JSP
  14. How a C++ compiler implements exception handling
  15. Cocos2d-x在线粒子编辑器
  16. Ant 基本语法的使用示列
  17. LDOOP设置关联后超出新起一页LinkNewPage
  18. hdu5306 Explosion
  19. Python学习—基础篇之文件操作
  20. Junit测试的理解------java基础知识

热门文章

  1. The differentiation program with abstract data
  2. C# httpwebrequest post 传输百分号‘%’
  3. andriod 下一个页面
  4. Lua中的元表和元方法
  5. web小流量实验方案
  6. jquery城市选择案例
  7. STL源码剖析——hashtable
  8. Python学习(六)模块 —— 第三方库
  9. feedparser win7 python 安装
  10. Tomcat 之 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099;