0

I have been trying to implement JaCoCo offline code coverage in a JBoss server using an instrumented EAR for deployment and the jacococagent.jar in order to track code coverage of external integration testing running against said JBoss.

I have been following guides such as these:

http://www.eclemma.org/jacoco/trunk/doc/offline.html

http://automationrhapsody.com/code-coverage-with-jacoco-offline-instrumentation-with-maven/

I feel I am pretty close as everything SEEMS to be working, however, when I load the coverage report up in eclipse's EclEmma plugin, it reports as 0 coverage for everything (which I know is wrong).

Here's my setup:

Here's the maven plugin configuration:

                <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <configuration>
                    <!-- <destFile>${sonar.jacoco.reportPath}</destFile> -->
                    <append>true</append>

                    <excludes>
                        <exclude>**/dao/**/*Dao*</exclude>
                        <exclude>**/dao/**/*DAO*</exclude>
                        <exclude>**/dao/**/*Vo*</exclude>
                        <exclude>**/dao/**/*VO*</exclude>
                        <exclude>**/ui/**/*</exclude>
                        <exclude>**/*Vo.*</exclude>
                        <exclude>**/*VO.*</exclude>
                        <exclude>**/test/**/*</exclude>
                        <exclude>**/tester/**/*</exclude>
                    </excludes>

                </configuration>
                <executions>
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.reportPath}</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unit-test-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${sonar.jacoco.reportPath}</dataFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>jacoco-instrument</id>
                        <phase>test</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                        <configuration>
                            <skip>${jacoco.skip.instrument}</skip>
                            <!-- <skip>false</skip> -->
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Here's my jacoco-agent.properties file:

destfile=/stage/live_integration_jacoco.exec
output=file
dumponexit=true
append=true

I'm bundling the JaCoCo Agent JARs right inside the EAR as these dependencies (the second one is just what jacocoagent.jar is labelled as in our repository):

        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <version>${jacoco.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jacoco.build</groupId>
            <artifactId>org.jacoco.jacocoagent</artifactId>
            <version>${jacoco.version}</version>
        </dependency>

Here's my process:

I run this on the project: mvn clean install -U -Djacoco.skip.instrument=false

And that generates my instrumented EAR artifact. I have verified that the classes in there are indeed instrumented by JaCoCo by decompiling a few of them.

I take that EAR that has instrumented code, the jacococagent.jar included in it, and the jacoco-agent.popreties file included as well and deploy that to JBoss. JBoss starts just fine (it used to get ClassNotFound exception before I started bundling jacocoagent.jar in it directly).

The "/stage/live_integration_jacoco.exec" file is created at this point with a size of '0'.

I run some tests on and against the server, even some manual testing, then stop the application.

The "/stage/live_integration_jacoco.exec" file now has data (30-60kb of data so far in my observations).

I import that exec file into eclipse and it loads without any errors and shows the classes in the project, however it reports 0 coverage on everything.

Well, I'm not sure what else to try at this point.

Does anyone have some thoughts on how to get it correctly generating the coverage report in my situation?

Thanks!

1 Answer 1

0

I suspect that classes deployed on server are compiled with Oracle Java compiler, while classes in Eclipse are compiled with Eclipse Java compiler, and hence JaCoCo can't associate them since they differ. To confirm this - you can try to generate report using the exec file that you try to import, but outside of Eclipse using Ant or Maven. And make sure that you execute generation of report on original (non instrumented) classes, otherwise they also won't match.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for the response. I've verified that the classes are non-instrumented when importing the exec file. I've tried to using my exec file to generate a report with maven, but I must be doing something wrong as I can't get it to work right. Do you have an example of that being done through maven? Maybe I'm looking up the wrong command...
Execute mvn jacoco:report -Djacoco.dataFile=/stage/live_integration_jacoco.exec in the module for which you want to generate report.
OK, I have been using mvn jacoco:report, but I can't get it to work for me. For example, I run mvn jacoco:report -Djacoco.dataFile="C:\development\live_integration_jacoco.exec" -DoutputDirectory="C:\development\JaCoCo-Output" yet for every module the output says [INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (default-cli) @ module-name --- [INFO] Skipping JaCoCo execution due to missing execution data file.
Sorry, user parameter "jacoco.dataFile" has been added recently and not yet released (eclemma.org/jacoco/trunk/doc/changes.html), but to make it available in earlier versions you can do <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <configuration> <dataFile>${jacoco.dataFile}</dataFile> </configuration> </plugin>
Thanks for the tips, I finally got around to adding that value in the POM and it did indeed generate the HTML reports, yet it still shows everything as 0% coverage...Hmmm...back to the drawing board, I guess...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.