0

我想在我的项目中进行测试覆盖。我创建了个人资料:我的 pom xml 个人资料是:

    <profile>
        <id>test-coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven.surefire.plugin.version}</version>
                    <configuration combine.self="override">
                        <redirectTestOutputToFile>true</redirectTestOutputToFile>
                        <testFailureIgnore>true</testFailureIgnore>
                        <argLine>
                            -Xms128m -Xmx1G -XX:MaxPermSize=128M
                        </argLine>

                           <groups>com.project.test.annotation.QuickTest</groups>

                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.1.201405082137</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

            </plugins>
        </build>

    </profile>

我正在运行这些命令: mvn clean install -DfailIfNoTests=false -P test-coverage mvn sonar:sonar

我无法获得测试覆盖率,我错过了什么?我的声纳版本:4.3

4

3 回答 3

2

您遇到的主要问题是argLinesurefire maven插件的属性的定义,应该将其设置为属性,而不是在插件的配置中。因为当您这样做时,JaCoCo maven 插件无法设置 argline 来配置其代理。

所以 argLine 应该在你的 pom.xml 中定义为一个属性。

有关更多详细信息,请参阅http://docs.sonarqube.org/display/SONAR/JaCoCo+Plugin

于 2014-08-18T14:26:34.797 回答
0

您应该能够将 jacoco 侦听器添加到 surefire 插件,例如

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <!-- Minimal supported version is 2.4 -->
  <version>2.13</version>
  <configuration>
    <properties>
      <property>
        <name>listener</name>
        <value>org.sonar.java.jacoco.JUnitListener</value>
      </property>
    </properties>
  </configuration>
</plugin>
于 2014-08-19T06:05:14.613 回答
0

只需将您的 argline 设置为如下所示

<argLine>
     ${argLine} -Xms128m -Xmx1G -XX:MaxPermSize=128M
</argLine>

这样,当 JaCoCo 为其代理设置 argLine 时,您不会覆盖它,您只需将您的附加到它。

于 2016-04-13T14:40:07.403 回答