我一直在尝试使用 Maven 在本地 Jenkins 服务器上设置代码覆盖率。我的测试似乎没有包含在覆盖率报告中。
我的 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>
在我的 Jenkins 服务器上,我有以下内容: Jenkins 配置:声纳声纳名称:声纳本地 3.5.1 服务器网址:http://local host:9000
项目级别:发布 Cobertura Coverate 报告:xml 报告模式:**/target/site.covertura/coverage.xml
但是当我运行 maven 任务“mvn cobertura:cobertura”或在 Jenkins 中查看声纳报告时,所有的覆盖率都是 0%,这让我觉得我的单元和集成测试没有被看到。
这是我的 pom 分离单元测试和集成测试的方式的问题吗?