我使用的是maven -尽力而为-插件版本2.17与maven。
我正在使用jacoco maven-plugin来分析我的junit测试:
在我的pom.xml中设置的jacoco插件如下所示:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<executions>
<execution>
<id>agent-for-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.reportPath}</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>我在src/main/java/this/excel下有一个类,如下所示:
package something.excel;
public class VDHTCStyle
{
public int doSomething() {
int i=0;
return i+7;
}
}我在src/ test /java/this/excel下的测试类如下所示:
package something.excel;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class VDHTCStyleStyleTest
{
private VDHTCStyleStyle vDHTCStyleStyle;
@Before
public void setUp()
{
vDHTCStyleStyle = new VDHTCStyleStyle();
}
@Test
public void shouldDoSomething() {
int something = vDHTCStyleStyle.doSomething();
assertEquals(something, 7);
}
}当我用
mvn clean install我在日志里看到了这个:
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ xxxxx ---
[INFO] Surefire report directory: /var/lib/jenkins/workspace/xxxx/modules/xx/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running something.excel.VDHTCStyleTest
|classnames | 2.2.3 | A simple utility for conditionally joining classNames together|
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.062 sec - in something.excel.VDHTCStyleTest 现在,如果我查看生成的jacoco报告文件,我会看到如下所示:
GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED,INSTRUCTION_COVERED,BRANCH_MISSED,BRANCH_COVERED,LINE_MISSED,LINE_COVERED,COMPLEXITY_MISSED,COMPLEXITY_COVERED,METHOD_MISSED,METHOD_COVERED
Module: xxx,something.excel,VDHTCStyleStyle,9,0,0,0,3,0,2,0,2,0据我所知,它认为没有涵盖任何一行、指令、分支或方法。
为什么?(帮助:)
发布于 2016-06-06 17:43:08
问题似乎在于,当在多模块项目中指定两次时,maven-surefire-plugin的行为是不可预测的。
我的父pom在build部分中有它,子模块pom在build部分也有它。因此,它似乎在运行测试,但是子模块中的覆盖率总是为0。
修复方法是从子模块pom中删除maven-surefire-plugin,并且只在父pom的构建部分中使用它。
问题解决了。
https://stackoverflow.com/questions/37595883
复制相似问题