SonarQube 4.1 + Teamcity - 单位测试覆盖率0.0%单位测试成功率100.0%

时间:2014-01-29 17:52:50

标签: maven sonarqube

我们在Teamcity构建目录中使用maven sonar插件来分析我们的java构建。 一切看起来都不错,除了单元测试覆盖率。

仪表板显示覆盖率为0%,单位测试成功率为100%。

任何指针?

SonarQube 4.1

1 个答案:

答案 0 :(得分:1)

如果您使用的是maven,则应在声纳任务之前运行 mvn clean install

mvn clean install声纳:声纳

在pom.xml中添加以下配置:

<properties>
    <sonar.jacoco.reportPath>${project.build.directory}/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPath>
</properties>

<build>
    <plugins>                                   
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>${surefireArgLine}</argLine>
                <excludes>
                    <exclude>**/*IT.java</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.6.0.201210061924</version>
            <executions>
                <execution>
                    <id>pre-unit-test</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${sonar.jacoco.reportPath}</destFile>
                        <propertyName>surefireArgLine</propertyName>
                    </configuration>
                </execution>
                <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${sonar.jacoco.reportPath}</dataFile>
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                    </configuration>
                </execution>
                <execution>
                    <id>pre-integration-test</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${sonar.jacoco.itReportPath}</destFile>
                        <propertyName>failsafeArgLine</propertyName>
                    </configuration>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${sonar.jacoco.itReportPath}</dataFile>
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.6.0.201210061924</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>