我一直在试图在我的本地Jenkins服务器上用Maven设置代码覆盖率。我的测试似乎没有被纳入报道报道。Cobertura代码覆盖率是错误的
我在我的pom.xml如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<check>
<haltOnFailure>false</haltOnFailure>
<totalLineRate>85</totalLineRate>
</check>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
<executions>
<execution>
<id>clean</id>
<phase>pre-site</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>instrument</id>
<phase>site</phase>
<goals>
<goal>instrument</goal>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
这里是我定义要运行
<plugin>
<!-- Separates the unit tests from the integration tests. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
<trimStackTrace>false</trimStackTrace>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test*.java</include>
</includes>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
而且我詹金斯服务器上的测试,我有以下几点: 詹金斯配置: 声纳 声纳名称:声纳本地3.5.1 服务器网址:http://local host:9000
项目级别: 发布的Cobertura Coverate报告: XML报告模式:** /目标/ site.covertura/coverage.xml
但是当我运行无论是Maven的任务 “MVN的Cobertura:的Cobertura” 或查看声纳詹金斯报道,所有的覆盖率都在0%,这让我觉得我的单元和集成测试没有被看到。
这是我的pom分离单元和集成测试的问题吗?
好吧,我已经用JaCoco替换了我的cobertura用法(使它看起来就像你的pom.xml示例),并尝试使用“mvn clean package”运行,但现在所有的测试都运行了,但没有为Jenkins生成.exec报告显示。 – sonoerin
你是否在声纳中看到报告?是你的jacoco插件配置为“\ * \ */\ * \ *。dump”(用于exec文件的路径?) – twillouer
不知道我做了什么,但它现在似乎正在工作。如果我看一下Sonar而不是Jenkins,我可以看到在代码覆盖范围内运行的测试(单元和集成)的数量。非常感谢你的帮助。您发布的帖子比我试图通过的许多教程更有帮助! – sonoerin