一. 下载maven
$ jumbo install apache-maven
二. 构建mvn项目
$ mkdir maven_project
$ cd maven_project
$ vim pom.xml; #输入一下内容
$ mkdir src/main/java/se/sigma/calculator/
$ vim src/main/java/se/sigma/calculator/Calculator.java;#输入一下内容:
package se.sigma.calculator;
public class Calculator {
public int nextFibonacci(int a, int b) {
int sum = a + b;
return sum;
}
public int sum(int a, int b) {
return a + b;
}
}
$ mkdir test/java/se/sigma/calculator/
$ vim test/java/se/sigma/calculator/CalculatorTest.java;#输入以下内容:
package se.sigma.calculator;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class CalculatorTest {
@Test
public void shouldCalculateFibonacci() {
Calculator calculator = new Calculator();
int expected = 13;
int actual = calculator.nextFibonacci(5, 8);
assertThat(actual, is(expected));
}
}
三. 生成覆盖率
$ mvn cobertura:cobertura
四. 访问覆盖率统计数据
$ cd target/site/cobertura/index.html
五. 在jenkins上配置,类似于下方:
六. 效果展示