1

我已按照说明为我们的声纳项目启用单元和集成测试:http: //docs.sonarqube.org/display/PLUG/Code+Coverage+by+Integration+Tests+for+Java+Project

我的 pom 设置几乎与此示例中给出的设置相同: https ://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/combined%20ut-it/combined- ut-it-multimodule-maven-jacoco

父pom设置:

        <profile>
        <id>code-coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <configuration>
                        <append>true</append>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default-prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-agent-for-it</id>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-report</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <excludes>
                                    <exclude>static/**/*.jar</exclude>
                                    <exclude>static/**/*.class</exclude>
                                </excludes>
                            </configuration>
                            </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

我们有一个特定的模块将运行集成测试:

        <profile>
        <id>code-coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <configuration>
                        <!-- The destination file for the code coverage report has to be set to the same value
                            in the parent pom and in each module pom. Then JaCoCo will add up information in
                            the same report, so that, it will give the cross-module code coverage. -->
                        <destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

我已将 Sonar 配置为查找 UT 和 IT: 在此处输入图像描述

单元测试被报告得很好,但不是集成测试。在 Bamboo 日志中,我可以看到声纳正在所有子模块中寻找集成测试和单元测试,但是当它到达父模块时,它从不运行 JaCoCoSensor 或 JaCoCoItSensor。这两个传感器都针对每个模块项目运行。我还注意到每个模块项目都有一个 JaCoCoOverallSensor 运行,而不是父项目。

如何让 JaCoCoItSensor 为父项目运行?

4

1 回答 1

1

我添加了一些配置属性,它开始工作。

父 pom.xml 添加:

<properties>
    ...
    <sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
    <sonar.language>java</sonar.language>
</properties>

我更改的 IT 测试模块:

<destFile>${sonar.jacoco.itReportPath}/../target/jacoco-it.exec</destFile>

对此:

<destFile>${sonar.jacoco.itReportPath}</destFile>
于 2015-12-24T16:43:33.970 回答