当前位置: 首页 > 知识库问答 >
问题:

雅可测试覆盖率报告显示 0%

汝墨一
2023-03-14

我必须获得应用程序的代码覆盖率,而业务测试是从不同的代码库执行的。

我使用:Maven作为我的构建Jbehave作为我的测试框架。测试是用java编写的。

我的应用程序是部署在tomcat上的一组war文件。

应用程序代码库与测试代码库是分开的。

在获得覆盖范围时,我遵循以下步骤。

1使用maven编译测试代码。

2将应用程序类从构建位置(${app.code.dir}/目标/类)复制到${test.code.dir}/目标/类

[3]通过maven运行测试和jacoco报告

mvn构建:我一直保持

<profile>
        <id>coverage</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.6.3.201306030806</version>
                    <executions>
                        <execution>
                            <id>default-prepare-agent</id>
                            <phase>process-resources</phase>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <skip>false</skip>
                                <destFile>${basedir}/target/jacoco-coverage.exec</destFile>
                            </configuration>
                        </execution>
                        <execution>
                            <id>default-report</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <!-- <skip>true</skip> -->
                                <excludes>
                                    <exclude>com/mytest/bdt/**</exclude><!-- test classes -->
                                    <exclude>com/mytest/bdd/**</exclude><!-- test classes -->
                                </excludes>

                                <dataFile>${basedir}/target/jacoco-coverage.exec</dataFile>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

使用以下方式执行jAct测试:

    <plugin>
         <groupId>org.jbehave</groupId>
         <artifactId>jbehave-maven-plugin</artifactId>
        <version>${jbehave.core.version}</version>
            <dependencies>
                <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>1.2.16</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>unpack-view-resources</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>unpack-view-resources</goal>
                    </goals>
                </execution>
                <execution>
                    <id>embeddable-stories</id>
                    <phase>test</phase>
                    <configuration>
                        <includes>
                            <include>${embeddables5}</include><!--  TestSuite.java -->
                        </includes>
                        <excludes />
                        <ignoreFailureInStories>true</ignoreFailureInStories>
                        <ignoreFailureInView>true</ignoreFailureInView>
                        <threads>1</threads>
                        <metaFilters>
                            <metaFilter>${meta.filter}</metaFilter>
                            <metaFilter>-skip *</metaFilter>
                            <metaFilter>+run</metaFilter>
                        </metaFilters>
                    </configuration>
                    <goals>
                        <goal>run-stories-as-embeddables</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

当我执行mvn mvn安装-Poverage时

执行过程如下。

[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ test-bdd-testsuite ---
[INFO] --- jbehave-maven-plugin:3.7.5:unpack-view-resources (unpack-view-resources) @ test-bdd-testsuite ---
[INFO] --- jacoco-maven-plugin:0.6.3.201306030806:prepare-agent (default-prepare-agent) @ test-bdd-testsuite ---
[INFO] argLine set to -javaagent:/home/testUser/.m2/repository/org/jacoco/org.jacoco.agent/0.6.3.201306030806/org.jacoco.agent-0.6.3.201306030806-runtime.jar=destfile=/home/testUser/testProj/trunk/target/jacoco-coverage.exec
[INFO] 
[INFO] --- maven-compiler-plugin:2.1:compile (default-compile) @ test-bdd-testsuite ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ test-bdd-testsuite ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/testUser/testProj/trunk/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.1:testCompile (default-testCompile) @ test-bdd-testsuite ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ test-bdd-testsuite ---
[INFO] No tests to run.
[INFO] Surefire report directory: /home/testUser/testProj/trunk/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- jbehave-maven-plugin:3.7.5:run-stories-as-embeddables (embeddable-stories) @ test-bdd-testsuite ---
[INFO] Running stories as embeddables using embedder Embedder[ .....

.....
.....
Test execution log comes here .......
.....
.....

[INFO] Reports view generated with 1 stories (of which 0 pending) containing 25 scenarios (of which 0 pending)
[INFO] Meta filters excluded 0 stories and  24 scenarios
[WARNING] Failures in reports view: 0 scenarios failed
[INFO] 
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ test-bdd-testsuite ---
[INFO] Building jar: /home/testUser/testProj/trunk/target/test-bdd-testsuite-1.0.jar
[INFO] 
[INFO] --- jacoco-maven-plugin:0.6.3.201306030806:report (default-report) @ test-bdd-testsuite ---
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ test-bdd-testsuite ---
[INFO] Installing /home/testUser/testProj/trunk/target/test-bdd-testsuite-1.0.jar to /home/testUser/.m2/repository/com/testCode/bdd/test-bdd-testsuite/1.0/test-bdd-testsuite-1.0.jar
[INFO] Installing /home/testUser/testProj/trunk/pom.xml to /home/testUser/.m2/repository/com/testCode/bdd/test-bdd-testsuite/1.0/test-bdd-testsuite-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.134s
[INFO] Finished at: Tue Nov 26 19:18:28 IST 2013
[INFO] Final Memory: 14M/309M
[INFO] ------------------------------------------------------------------------

这样,我将获得与应用程序包一起生成的覆盖率报告。但覆盖率显示为 0%

在会话链接中未加载应用程序类。截图:

有人可以在这里帮助我吗?

共有1个答案

傅高逸
2023-03-14

我能够解决这个问题如下:

>

  • 将 中的应用程序类复制到规范html" target="_blank">文件夹中。

    用Java参数启动应用服务器(mycase中的tomcat)

    -javaagent:$WORKSPACE/target/lib/jacoco-agent-0.6.3.2.jar=includes=*,destfile=$‌​TOMCAT_HOME/jacoco-coverage.exec,append=false
    

    (我让Jacoco-agent jar在布局中复制到我的项目中)

    执行测试(这可以自动或手动)

    停止tomcat服务器(jacoco-coverage.exec此时更新)

    执行ant报告目标。指向更新的jacoco覆盖范围。执行并复制应用程序类文件夹。

    参考:http://car-online.fr/en/blog/fabien_duchene/2013-05-03-JavaTomcat JSP应用程序中的代码覆盖率,例如使用Jacoco的WebGoat/

    感谢@jens-schauder指点我将此作为答案发布。

  •  类似资料:
    • 问题内容: 从不同的代码库执行业务测试时,我必须获得应用程序的代码覆盖率。 我使用:Maven作为我的构建Jbehave作为我的测试框架。测试是用Java编写的。 我的应用程序是部署在tomcat上的一组war文件。 应用程序代码库与测试代码库是分开的。 为了获得覆盖范围,我遵循以下步骤。 1使用maven编译测试代码。 2将应用程序类从其构建位置($ {app.code.dir} / targe

    • 我尝试在我的应用程序模块中的代码的AndroidKotlin应用程序的声纳Qube中显示测试覆盖范围。我可以生成雅各的覆盖结果并显示声纳Qube分度仪,但问题是测试覆盖范围未显示在声纳Qube中: https://imgur.com/a/xOjxLl1 在我的项目的build.gradle中,我有: 在我的身体里。我的应用程序模块的gradle 我生成我的Jacoco报告: 并使用:生成我的son

    • v2.0 Codecov报表 , 从2017-12-29后开始统计 测试覆盖率为 : , 可以从 https://codecov.io/gh/apache/dubbo 页面得到覆盖率报表 v1.0 基于 2.0.12 版本,统计于 2012-02-03

    • 当使用 生成覆盖率报告后,我的测试在代码覆盖率报告中显示为100%覆盖,如下所示 我尝试将测试移动到它自己的文件夹中,但仍然会得到相同的结果 实际的单元测试不应该出现在覆盖率报告中,并且扭曲了我的覆盖率。它应该只显示实际程序的覆盖范围。

    • 我在测试android以创建覆盖率测试报告时遇到问题。我使用./gradlew createDebugCoverageReport命令创建覆盖率报告。已创建报告,但所有测试的结果均为%0。第一个设备已植根,但第二个设备未植根。我们使用这两个设备测试勺子,并查看勺子输出。所以这两个设备一起使用。问题:当我们使用第一个设备(根设备)运行此命令时,将按预期创建所有覆盖率测试结果,但当我们同时使用两个设备

    • Jacoco插件在jenkins报告中显示0%的覆盖率,但当我在本地系统中运行相同的命令时,Jacoco会正确生成报告。我正在使用以下命令: mvn-s xyz/settings.xml-f xyz/xyz/pom.xml清洁安装org.jacoco 所以当我在jenkins中运行这个命令时,它会生成错误的报告。我已经检查了它在工作区目录对应的项目在詹金斯。它显示每个项目的0%覆盖率。但是当我在本