Jenkins+Cobertura程式碼覆蓋率(學習筆記三十七)

sktj發表於2018-05-14

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 就會顯示覆蓋率報表


相關文章