简体   繁体   English

Jacoco代理不衡量任何代码覆盖率

[英]Jacoco agent does not measure any code coverage

During the maven build process I start my app using the process-exec-maven-plugin and run Integration tests with Failsafe. 在Maven构建过程中,我使用process-exec-maven-plugin启动我的应用程序,并使用Failsafe运行集成测试。 Now I want to get coverage data from the application under test. 现在,我想从被测应用程序中获取覆盖率数据。

The problem is, that the coverage report contains all the classes of my application but no coverage data (0% for all). 问题是,覆盖率报告包含我的应用程序的所有类,但没有覆盖率数据(全部为0%)。 When I append the jacoco agent to the failsafe plugin, it generates the code coverage for the test-classes which does not really help. 当我将jacoco代理附加到故障安全插件时,它会为测试类生成代码覆盖率,但实际上并没有帮助。

Any Ideas? 有任何想法吗?

process-exec-maven-plugin configuration: 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>

Using the following Jacoco configuration: 使用以下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>

In my case the problem was that the server was gone together with the docker container in "HW power off" style - there was no signal like SIGTERM on which depends output of JaCoCo (end of the JVM running in docker container). 在我的案例中,问题是服务器与“ HW关机”样式的Docker容器一起使用-没有像SIGTERM这样的信号依赖JaCoCo(在Docker容器中运行的JVM的结束)的输出。

When I add command "killall java" that docker runs inside the docker container and a small pause before the shutdown of the container, the exec file is alright. 当我添加命令“ killall java”使docker在docker容器内运行并且在关闭容器之前稍作停顿时,exec文件就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM