我有一个maven构建,其中包含多个项目,这些项目又包含许多子maven模块。在测试阶段,每个项目都将执行他们的测试并以编程方式生成junit测试报告,并将其放在 / target / surefire-reports / 中的相应模块目标文件夹中。在Jenkins构建的状态页面中构建成功后,我能够将测试结果看作图形。但问题是Jenkins没有采取所有生成的junit xml它只需要部分数量。我在整个构建中总共有850个测试用例,但它只在图表和测试结果中显示449个。它的原因是什么?
生成junit报告没有问题,所有测试用例都生成报告,但Jenkins无法识别所有。 Jenkins中的测试用例计数因每个构建而异,无需添加或删除任何测试文件。
仅供参考: 我手动生成junit报告。要通知Jenkins,我已经启用了maven sure fire插件,并在目标中的surefire-reports文件夹中添加了报告。我创建了 maven build project 而不是自由风格项目。
我有什么遗失的吗?
答案 0 :(得分:0)
我也遇到过这个问题,以下是我的第一个问题: http://javamemento.blogspot.no/2016/02/sonar-jacoco-maven-multi-module.html
所以你的pom应该是这样的:
paste0("Group_", 1 + c(0, cumsum(x[-length(x)] != x[-1])))
[1] "Group_1" "Group_1" "Group_1" "Group_2" "Group_2" "Group_2" "Group_3" "Group_4" "Group_4" "Group_5" "Group_5"
此处的关键字是
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</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>agent-for-it</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<append>true</append>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
现在,您的所有数据都将存储在1个报告文件中。
确保您只在父pom中调用了maven-surefire-plugin。如果您将它包含在您的孩子的poms中,结果将被父pom覆盖。这里有更多怪癖:http://javamemento.blogspot.no/2016/06/sonar-maven-surefire-plugin-quirks.html
最后确保正确使用junit和void方法。测试方法或surefire的副作用会表现得很奇怪。 http://junit.org/junit4/faq.html#atests_4