3

我的信念是 JaCoCo Maven 插件check目标不支持多模块项目中的集成测试(其中集成测试与被测代码位于不同的模块中)。

我有一个具有以下结构的项目:

service
├── webapp
├── lib1
├── lib2
└── integration-test

webapp依赖lib1lib2构建到 WAR,integration-test使用内存容器来运行webapp和执行针对它的测试。

我的配置是这样的,JaCoCo 成功地为 { , , } 中的单元测试和运行的测试的集成测试覆盖生成合并数据文件(jacoco.execjacoco-it.execin ) 。service/target/webapplib1lib2integration-test

添加配置时,check我从插件中获得此输出。

[INFO] --- jacoco-maven-plugin:0.7.8:check (default-check) @ integration-test ---
[INFO] Skipping JaCoCo execution due to missing classes directory:/home/mark/workspace/service/integration-test/target/classes

错误是准确的,因为integration-test模块只有测试源,所以没有target/classes目录。添加源目录没有帮助,check失败表明覆盖率为 0%,因为目录中没有适用的类文件target/classes。从这个(并查看检查 Mojo 源)看来,check目标似乎需要classes它正在检测的所有模块的目录(webapp、、、lib1lib2

不存在这样的配置,check它允许我指定classes目录的位置,而且它看起来也不支持查看源代码的这种功能。

根/父pom.xml

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

<-- Note, I am using build/plugins/plugin - not build/pluginManagement/plugin

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.8</version>

    <executions>
        <execution>
            <id>agent-for-ut</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <append>true</append>
                <destFile>${sonar.jacoco.reportPath}</destFile>
            </configuration>
        </execution>
        <execution>
            <id>agent-for-it</id>
            <goals>
                <goal>prepare-agent-integration</goal>
            </goals>
            <configuration>
                <append>true</append>
                <destFile>${sonar.jacoco.itReportPath}</destFile>
            </configuration>
        </execution>
        <execution>
            <id>default-check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <phase>verify</phase>
            <configuration>
                <dataFile>${sonar.jacoco.itReportPath}</dataFile>
                <rules>
                    <rule>
                        <element>BUNDLE</element>
                        <limits>
                            <limit>
                                <counter>LINE</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.9800</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

integration-test pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.19.1</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
            <configuration>
                <skipTests>${skipTests}</skipTests>
                <argLine>${argLine} -Duser.timezone=UTC -Xms256m -Xmx256m</argLine>
                <reuseForks>false</reuseForks>
            </configuration>
        </execution>
    </executions>
</plugin>
4

0 回答 0