Jacoco Test coverage report shows 0%

Asanke

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

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

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 Compile the test code using maven.

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

[3] Run the tests and jacoco report through maven

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>

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>

When I execute mvn mvn install -Pcoverage

The execution goes as follows.

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

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:

Can some one help me here?

Asanke

I was able to resolve this as follows

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

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

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

  3. Execute the tests (this can be automated or manual)

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

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

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

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jacoco Test coverage report shows 0%

From Dev

JaCoCo Debug Coverage Test Report

From Dev

JaCoCo coverage report setups(exclude test classes)

From Dev

JaCoCo coverage report setups(exclude test classes)

From Dev

Jacoco generate coverage report for only a single test class

From Dev

Jacoco 0% Code Coverage

From Dev

Jacoco 0% Code Coverage

From Dev

Exclude folder in jacoco coverage report

From Dev

Jacoco Coverage and Report Task with Ant

From Dev

Jacoco coverage of unit test code

From Dev

jacoco coverage per test setup

From Dev

maven jacoco: not generating code coverage report

From Dev

maven jacoco plugin does not generate coverage report

From Dev

Display test coverage using jacoco in gradle

From Dev

Generate test coverage with Jacoco and Circle CI fails

From Dev

Why might Jacoco be showing a code coverage of 0?

From Dev

Gradle jacoco coverage report with more than one submodule(s)?

From Dev

Code Coverage Report with Jacoco for IntegrationTests runs on Weblogic server

From Dev

generating jacoco code coverage report for all sub modules

From Dev

Gradle jacoco coverage report with more than one submodule(s)?

From Dev

SonarQube coverage missing some lines covered by Jacoco report

From Dev

JUnit report to show test functionality, not coverage

From Dev

SonarQube: including a subset of test coverage classes in report

From Dev

How to generate test coverage report in Meteor / Velocity?

From Dev

Android test coverage report for multi module app

From Dev

How to add static member variables Jacoco Test Coverage?

From Dev

Unit test Coverage percentage %0

From Dev

0% code coverage jacoco4sbt 2.0.0, sbt 0.12.2

From Dev

JaCoCo 0% coverage for objects created with Jackson.map.ObjectMapper

Related Related

  1. 1

    Jacoco Test coverage report shows 0%

  2. 2

    JaCoCo Debug Coverage Test Report

  3. 3

    JaCoCo coverage report setups(exclude test classes)

  4. 4

    JaCoCo coverage report setups(exclude test classes)

  5. 5

    Jacoco generate coverage report for only a single test class

  6. 6

    Jacoco 0% Code Coverage

  7. 7

    Jacoco 0% Code Coverage

  8. 8

    Exclude folder in jacoco coverage report

  9. 9

    Jacoco Coverage and Report Task with Ant

  10. 10

    Jacoco coverage of unit test code

  11. 11

    jacoco coverage per test setup

  12. 12

    maven jacoco: not generating code coverage report

  13. 13

    maven jacoco plugin does not generate coverage report

  14. 14

    Display test coverage using jacoco in gradle

  15. 15

    Generate test coverage with Jacoco and Circle CI fails

  16. 16

    Why might Jacoco be showing a code coverage of 0?

  17. 17

    Gradle jacoco coverage report with more than one submodule(s)?

  18. 18

    Code Coverage Report with Jacoco for IntegrationTests runs on Weblogic server

  19. 19

    generating jacoco code coverage report for all sub modules

  20. 20

    Gradle jacoco coverage report with more than one submodule(s)?

  21. 21

    SonarQube coverage missing some lines covered by Jacoco report

  22. 22

    JUnit report to show test functionality, not coverage

  23. 23

    SonarQube: including a subset of test coverage classes in report

  24. 24

    How to generate test coverage report in Meteor / Velocity?

  25. 25

    Android test coverage report for multi module app

  26. 26

    How to add static member variables Jacoco Test Coverage?

  27. 27

    Unit test Coverage percentage %0

  28. 28

    0% code coverage jacoco4sbt 2.0.0, sbt 0.12.2

  29. 29

    JaCoCo 0% coverage for objects created with Jackson.map.ObjectMapper

HotTag

Archive