【问题标题】:Jenkins jacoco plugin empty reportJenkins jacoco 插件空报告
【发布时间】:2016-01-03 02:17:38
【问题描述】:

我有一个项目,我使用 Jacoco 来计算代码覆盖率。 我在这里使用 Maven 配置:

http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/

使用 Jenkins,我运行“mvn clean install test”。它在 /target/site/jacoco-ut/ 文件夹中生成报告。如果我打开 index.html 文件,我会看到:

但是当我在 jenkins 工作中打开 JaCoCo 覆盖率报告时,我看到了这个:

它说每个测试都覆盖了 0% 的代码。我不明白为什么我的结果与 html 报告中的结果不同。

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.5.201505241946</version>
            <executions>
                <!--
                    Prepares the property pointing to the JaCoCo runtime agent which
                    is passed as VM argument when Maven the Surefire plugin is executed.
                -->
                <execution>
                    <id>pre-unit-test</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                        <!--
                            Sets the name of the property containing the settings
                            for JaCoCo runtime agent.
                        -->
                        <propertyName>surefireArgLine</propertyName>
                    </configuration>
                </execution>
                <!--
                    Ensures that the code coverage report for unit tests is created after
                    unit tests have been run.
                -->
                <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.15</version>
            <configuration>
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <id>surefire-unit-tests</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the VM argument line used when unit tests are run. -->
                        <argLine>${surefireArgLine}</argLine>
                        <!-- Skips unit tests if the value of skip.unit.tests property is true -->
                        <skipTests>${skip.unit.tests}</skipTests>
                        <!-- Excludes integration tests when unit tests are run. -->
                        <skip>false</skip>
                        <excludes>
                            <exclude>**/*IntegrationTests.java</exclude>
                        </excludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.15</version>
            <executions>
                <!--
                    Ensures that both integration-test and verify goals of the Failsafe Maven
                    plugin are executed.
                -->
                <execution>
                    <id>integration-tests</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the VM argument line used when integration tests are run. -->
                        <argLine>${failsafeArgLine}</argLine>
                        <!--
                            Skips integration tests if the value of skip.integration.tests property
                            is true
                        -->
                        <skipTests>${skip.integration.tests}</skipTests>
                    </configuration>
                </execution>
            </executions>
        </plugin>

还有我的詹金斯配置:

我的错误是什么?

【问题讨论】:

    标签: maven jenkins jacoco


    【解决方案1】:

    我遇到了类似的问题,只需将“jacoco-maven-plugin”版本更新为 0.7.7.201606060606 并将“maven-surefire-plugin”版本更新为 2.19.1 即可解决

    我希望这对你有用。

    【讨论】:

      【解决方案2】:

      我发现了一个与我的问题类似的 jenkins 问题:

      https://issues.jenkins-ci.org/browse/JENKINS-28652

      错误是jacoco版本引起的。 版本 0.7.5.201505241946 被窃听。 我切换到版本 0.7.4.201502262128 现在它可以工作了。

      【讨论】:

        【解决方案3】:
        Try to use in Jenkins Plugin : 
        Path to exec files  = **/**.exec
        

        我使用这个 pom:

        <jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>
            <jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file>
        
            <plugin>
                            <groupId>org.jacoco</groupId>
                            <artifactId>jacoco-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>pre-integration-test</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>prepare-agent-integration</goal>
                                    </goals>
                                    <configuration> 
                                        <destFile>${jacoco.it.execution.data.file}</destFile> 
                                        <propertyName>failsafeArgLine</propertyName>
                                    </configuration>
                                </execution>
                                <!-- Ensures that the code coverage report for integration tests after -->
                                <!--  integration tests have been run. -->
                                <execution>
                                    <id>post-integration-test</id>
                                    <phase>post-integration-test</phase>
                                    <goals>
                                        <goal>report-integration</goal>
                                    </goals>
                                    <configuration> 
                                        <dataFile>${jacoco.it.execution.data.file}</dataFile> 
                                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
        

        【讨论】:

        • 你为什么要这样做:mvn clean install test,你可以这样做:mvn clean install
        • 我做了一个“mvn clean install test”,因为我使用的教程说“命令 mvn clean test 运行单元测试并创建单元测试的代码覆盖率报告到目录 target/site/jacoco- ut”。
        猜你喜欢
        • 2015-10-04
        • 2018-09-13
        • 2018-12-18
        • 2015-08-03
        • 1970-01-01
        • 1970-01-01
        • 2017-10-19
        • 2015-12-25
        • 2018-09-05
        相关资源
        最近更新 更多