Jacoco测试覆盖率报告显示0% [英] Jacoco Test coverage report shows 0%

查看:1547
本文介绍了Jacoco测试覆盖率报告显示0%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to get the code coverage of a application while business test are executed from a different code base.

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

I use: Maven as my build Jbehave as my testing framework. The test are written in java.

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

My application is a set of war files deployed on tomcat.

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

The application code base is separate from test code base.

在获得覆盖范围时,我按照以下步骤进行操作。

In getting the coverage I followed the below steps.

1 使用maven编译测试代码。

1 Compile the test code using maven.

2 从构建地点复制应用程序类( $ {app.code.dir} / target / classes)到$ {test.code.dir} / target / classes

2 Copy application classes from the place it was build (${app.code.dir}/target/classes) to ${test.code.dir}/target/classes

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

[3] Run the tests and jacoco report through maven

mvn构建:我保留了

The mvn build: I have kept

<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>

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

The jbehave test are executed using :

    <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 install -Pcoverage

When I execute mvn mvn install -Pcoverage

执行如下。

[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%

With this I get a coverage report generated with the application packages. But the coverage is shown as 0%

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

In the session link the application classes are not loaded. Screenshots:

有人可以帮我吗?

推荐答案

我能够按如下方式解决此问题

I was able to resolve this as follows


  1. 将应用程序类复制到检测文件夹中。

  1. Copy the application classes in to a instrumentation folder.

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

Start the app server (tomcat in mycase) with Java arguments

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

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

(I had the jacoco-agent jar copied in to my project at the layout)

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

Execute the tests (this can be automated or manual)

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

Stop the tomcat server (jacoco-coverage.exec is updated at this point)

执行ant报告目标。指向更新的jacoco-coverage.exec和复制的应用程序类文件夹。

Execute ant report target. pointing the updated jacoco-coverage.exec and copied application class folder.

参考: http://car-online.fr/en/blog/fabien_duchene/2013-05-03-Java%20Code%20Coverage%20in%20Tomcat%20JSP%20applications,%20e.g.,%20WebGoat%20with %20Jacoco /

感谢@ jens-schauder指示我发布此答案。

Thanks @jens-schauder for pointing me to post this as the answer.

这篇关于Jacoco测试覆盖率报告显示0%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆