1

在 Maven 构建过程中,我使用process-exec-maven-pluginFailsafe 启动我的应用程序并运行集成测试。现在我想从被测应用程序中获取覆盖率数据。

问题是,覆盖率报告包含我的应用程序的所有类,但没有覆盖率数据(全部为 0%)。当我将 jacoco 代理附加到故障安全插件时,它会为测试类生成代码覆盖率,这并没有真正的帮助。

有任何想法吗?

process-exec-maven-plugin 配置:

    <plugin>
        <groupId>com.bazaarvoice.maven.plugins</groupId>
        <artifactId>process-exec-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>start-importer</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>start</goal>
                </goals>
                <configuration>
                    <name>product-importer</name>
                    <waitForInterrupt>false</waitForInterrupt>
                    <healthcheckUrl>http://localhost:${jetty.http.port}/health</healthcheckUrl>
                    <arguments>
                        <argument>${java.home}/../bin/java</argument>
                        <argument>${failsafe.argLine}</argument>
                        <argument>-jar</argument>
                        <argument>
                            ${project.build.directory}/jars/app-${project.version}-shaded.jar
                        </argument>
                    </arguments>
                </configuration>
            </execution>
            <!--Stop all processes in reverse order-->
            <execution>
                <id>stop-all</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>stop-all</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

使用以下 Jacoco 配置:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>prepare-jacoco-service-test-agent</id>
            <!-- default pre-integration is to late for the process-exec-maven-plugin -->
            <phase>package</phase>
            <goals>
                <goal>prepare-agent-integration</goal>
            </goals>
            <configuration>
                <propertyName>failsafe.argLine</propertyName>
                <includes>
                    <include>de.myapp.*</include>
                </includes>
                <classDumpDir>${project.build.outputDirectory}</classDumpDir>
                <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
                <append>true</append>
            </configuration>
        </execution>

        <execution>
            <id>report-jacoco-service-test-results</id>
            <goals>
                <goal>report-integration</goal>
            </goals>
            <phase>verify</phase>
            <configuration>
                <dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
                <outputDirectory>${project.build.directory}/coverage-reports/out/</outputDirectory>
            </configuration>
        </execution>

    </executions>
</plugin>
4

1 回答 1

0

在我的情况下,问题是服务器以“HW power off”样式与 docker 容器一起消失了 - 没有像 SIGTERM 这样的信号依赖于 JaCoCo 的输出(在 docker 容器中运行的 JVM 结束)。

当我添加 docker 在 docker 容器内运行的命令“killall java”并在容器关闭之前稍作停顿时,exec 文件就可以了。

于 2018-10-13T18:39:09.597 回答