Jacoco测试覆盖率报告显示0%

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

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

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

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

在获得报道时,我遵循以下步骤。

1使用maven编译测试代码。

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

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

mvn版本:我保留了

 coverage  false     org.jacoco jacoco-maven-plugin 0.6.3.201306030806   default-prepare-agent process-resources  prepare-agent   false ${basedir}/target/jacoco-coverage.exec    default-report post-integration-test  report   <!-- true -->  com/mytest/bdt/** com/mytest/bdd/**  ${basedir}/target/jacoco-coverage.exec        

使用以下命令执行jbehave测试:

   org.jbehave jbehave-maven-plugin ${jbehave.core.version}   log4j log4j 1.2.16     unpack-view-resources process-resources  unpack-view-resources    embeddable-stories test   ${embeddables5}   true true 1  ${meta.filter} -skip * +run    run-stories-as-embeddables     

当我执行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 ------------------------------------------------------- TESTS ------------------------------------------------------- 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. 将应用程序类复制到检测文件夹中。

  2. 使用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复制到我的项目布局中)

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

  4. 停止tomcat服务器( jacoco-coverage.exec更新jacoco-coverage.exec

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

参考: 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指示我发布这个作为答案。