0

我继承了一个奇怪的 Maven 多模块项目。标准业务类和单元测试位于一个名为“代码”的模块中,我们为该模块提供了很好的简单工作声纳指标。第二个模块包含针对部署的 glassfish 服务器运行的各种集成样式测试,这些测试在 integ-test 模块中作为单元测试运行。

pom.xml // root level,
    code // business code and unit tests :-)
        moduleA
        moduleB
    integ-test // ;-(
        moduleA
        moduleB

我知道最简单的选择是将“集成测试”类移动到“代码”模块中,并将它们重构为真正的集成测试,但目前这不是一个选择。

我已经找到了一种方法来记录“integ-tests”模块的代码覆盖级别,方法是使用 jacoco:dump 目标将 jacococ.exec 下载到 integ-test 模块。

我的 maven pom 结构现在看起来像这样

 pom.xml // defined jacoco verify -> report goal
     code // business code and unit test
         moduleA
            target/jacoco.exec - unit test coverage
            pom.xml
     pom.xml - defines standard jacoco prepare-agent goal
     integ-test //
         moduleA
            target/jacoco.exec - really integration test coverage
            pom.xml
     pom.xml- defines jacoco dump and merge

我目前的方法是合并“integ-test”模块中的所有 jacococ.exec 文件,并使用“destFile”值将这些详细信息保存为“code”模块作为 jacoco-it.exec 文件。然后,标准的 sonar:sonar 目标应该选择该文件并将其用作集成测试覆盖率。

 pom.xml
     integ-test
         moduleA
            target/jacoco.exec - really integration test coverage modA
         moduleB
            target/jacoco.exec - really integration test coverage modB
     code
         moduleA
         moduleB
     target/jacoco-it.exec - This should be the merged content of the two files above
     pom.xml

我的根级别 pom.xml 定义了这个 jacoco-maven-plugin 配置

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
        <append>true</append>
        <includes>
            <include>com/a/b/c/**</include>
        </includes>
    </configuration>
    <executions>

        <execution>
            <id>jacoco-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>

        <execution>
            <id>jacoco-dump</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>dump</goal>
            </goals>
        </execution>

        <execution>
            <id>jacoco-merge</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>merge</goal>
            </goals>
            <configuration>
                <fileSets>
                    <fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
                        <directory>${project.basedir}/integ-test</directory>
                        <includes>
                            <include>*.exec</include>
                        </includes>
                    </fileSet>
                </fileSets>
                <destFile>${sonar.jacoco.itReportPath}</destFile>
            </configuration>
        </execution>

        <execution>
            <id>jacoco-site</id>
            <phase>verify</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

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

我已将 jacoco:merge 目标链接到 maven 后集成测试阶段,以确保在运行测试后进行合并,但始终在“integ-test”文件夹中创建“jacoco-it.exec”文件.

有什么建议么?

4

1 回答 1

0

指向主 pom 目标目录中的 destFile 怎么样?只需定义

<configuration>
    <append>true</append>
    <destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
    <propertyName>jacoco.integrationtest.arguments</propertyName>
</configuration>

在子项目中。所有覆盖数据都将附加在 jacoco-it.exec 文件中。此文件由 sonarqube 拾取,您将看到覆盖范围为 IT 覆盖范围。您也可以使用 jacoco.exec 作为文件名。

于 2015-07-13T08:24:50.590 回答