您现在的位置是:首页 > 文章详情

Jenkins +Cobertura代码覆盖率(学习笔记三十七)

日期:2018-05-13点击:352

https://www.cnblogs.com/testway/p/6380656.html

1、新建一个maven工程,在src/main/java 下建一个CoverageTest.java 类

package test_junit;publicclass CoverageTest {

    public CoverageTest() {

        // TODO Auto-generated constructor stub    }

    publicstaticvoid main(String[] args) {

        // TODO Auto-generated method stub    }


    publicstaticinttestadd(intx,int y){

        intc = 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.

*/publicclass JunitTest {

    @Test

    publicvoid testadd(){

        intb = CoverageTest.testadd(5, 20);

        Assert.assertEquals(b,50);

    }

}

3、pom.xml 文件

4.0.0testunittest_junit1.0-SNAPSHOTjenkinsenv.BUILD_NUMBERorg.codehaus.mojocobertura-maven-plugin2.7xmlpackagecoberturajunitjunit4.12

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

原文链接:https://yq.aliyun.com/articles/660933
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章