我有一个包含多个测试和Cobertura Maven Plugin的项目。一切正常,但一个类的测试让我发疯。
这是覆盖率 83% 的 cobertura 报告:
这是基本测试:
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class TimeHelperTest {
@Test
public void elapsedMillisToHumanExpression() throws Exception {
assertEquals("0 min 3 seg 600 millis",
TimeHelper.elapsedMillisToHumanExpression(1000000000l, 1000003600l));
}
}
问题
- cobertura报告中类名左侧的0是什么意思?
其他类显示数字 > 0 并且是绿色的。
环境
- 爪哇 8
- ubuntu
- 蚀
- pom.xml
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>90</branchRate>
<lineRate>90</lineRate>
<totalBranchRate>90</totalBranchRate>
<totalLineRate>90</totalLineRate>
<packageLineRate>90</packageLineRate>
<packageBranchRate>90</packageBranchRate>
</check>
<formats>
<format>html</format>
</formats>
</configuration>
<executions>
<execution>
<id>cobertura-clean-and-check</id>
<phase>prepare-package</phase>
<goals>
<goal>clean</goal>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
尝试
我尝试在我的@Test 中进行一些更改,但报告没有改变!
- 利用
extends TestCase
- 利用
@RunWith
- 使用maven-surefire-plugin包括 **/*Test.java
- 删除 pom.xml 中的阈值
研究
- 使用 Maven 3 时 Cobertura 代码覆盖率为 0%
- https://github.com/cobertura/cobertura/issues/136
- http://cobertura.996293.n3.nabble.com/Cobertura-shows-zero-code-coverage-despite-all-tests-running-td2829.html
- This talk about the base path of test for ant projects but I can't use it in my maven project