Cobertura + jenkins 单元测试代码覆盖率统计
2024-10-19 01:33:05
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 就会显示覆盖率报表
最新文章
- List [][]
- highlight高亮风格
- 使用jQuery解析JSON数据
- datatables增删改查的实现
- Android经典完美退出方法
- Sigmaplot激活码获取地址
- 16 SQL Tuning Overview
- Web Service和WCF的到底有什么区别
- JavaWeb学习总结(三十五)——使用JDBC处理Oracle大数据
- ios真机调试详细步骤
- Linq101-Partitioning
- ThinkPhp3.2 无法加载模块:Index
- J2EE基础总结(4)——JSP
- How a C++ compiler implements exception handling
- Cocos2d-x在线粒子编辑器
- Ant 基本语法的使用示列
- LDOOP设置关联后超出新起一页LinkNewPage
- hdu5306 Explosion
- Python学习—基础篇之文件操作
- Junit测试的理解------java基础知识
热门文章
- The differentiation program with abstract data
- C# httpwebrequest post 传输百分号‘%’
- andriod 下一个页面
- Lua中的元表和元方法
- web小流量实验方案
- jquery城市选择案例
- STL源码剖析——hashtable
- Python学习(六)模块 —— 第三方库
- feedparser win7 python 安装
- Tomcat 之 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099;