Jacoco and integration tests using Jetty

1,771 views
Skip to first unread message

ocat...@gmail.com

unread,
Dec 3, 2013, 12:34:45 PM12/3/13
to jac...@googlegroups.com
Hi,

I can't collect data from my integration tests. My integration tests send request to a Jetty server (I test webservices). I would like Jacoco collect data from the classes invoked by Jetty.

For the moment, I have the configuration below. I think that I'm collecting the data from my integration tests that are executed by maven-failsafe-plugin. But I would like to record data from the implementation classes executed by Jetty.
How to add jvm args to jetty-maven-plugin so that Jacoco collects data from classes executed by Jetty ?
( Or, do I have to work with an embedded Jetty / or do I have to use maven-cargo-plugin ? )

Thanks for your help.

Regards,
Olivier


<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.ut.execution.data.file}</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.ut.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Failsafe plugin is executed.
-->
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.it.execution.data.file}</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for integration tests after
integration tests have been run.
-->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.it.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<!-- Used for unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<skipTests>${skip.unit.tests}</skipTests>
<!-- Excludes integration tests when unit tests are run. -->
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
</configuration>
</plugin>
<!-- Used for integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<!--
Ensures that both integration-test and verify goals of the Failsafe Maven
plugin are executed.
-->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Sets the VM argument line used when integration tests are run. -->
<argLine>${failsafeArgLine}</argLine>

<!--
Skips integration tests if the value of skip.integration.tests property
is true
-->
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.11.v20130520</version>
<configuration>
<webAppSourceDirectory>WebContent</webAppSourceDirectory>
<stopPort>9699</stopPort>
<stopKey>foo</stopKey>
<scanIntervalSeconds>0</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8081</port>
</connector>
</connectors>
<useTestClasspath>true</useTestClasspath>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
</plugin>

Marc R. Hoffmann

unread,
Dec 4, 2013, 2:50:19 PM12/4/13
to jac...@googlegroups.com
Hi,

using the prepare-agent goal is the right aproach to get a JaCoCo agent
configuration.

How you specify JVM args in Jetty or the Maven cargo plugin is a
question you may get better answers at the respective projects.

Cheers,
-marc

gaymailatga...@gmail.com

unread,
Dec 6, 2013, 7:41:35 AM12/6/13
to jac...@googlegroups.com, ocat...@gmail.com
Hi Olivier,
I was recently solving the same problem - how to collect coverage for integration tests. The usual approach with pom.xml produced some coverage reports, but the problem was that it only collected coverage for the _test_ classes. Bummer. So I dug deeper and noticed that I need to pass the argument to Jetty. I found the answer here:
http://stackoverflow.com/questions/2007192/maven-jetty-plugin-how-to-control-vm-arguments
If you have a recent version of Jetty, you can control the arguments form the pom, otherwise you'll have to set MAVEN_OPTS manually as suggested in the accepted answer.

So now you have the .exec file and you try to generate a report and bam!, there are still only the test classes, apparently not covered at all. If that happens, your integration test project is separated from the other one(s). What I did was to manually copy the classes from target folders of the other projects to the one of integration tests and run 'mvn jacoco:report'. This can probably be just as well specified in the pom as well, but I didn't try it.

Jan

Mirko Friedenhagen

unread,
Dec 6, 2013, 4:01:17 PM12/6/13
to jac...@googlegroups.com
Just a hint: for adding source files from one module to the source
path of another module, you may use the build-helper-maven-plugin, an
example may be seen at
https://github.com/1and1/testlink-junit/blob/master/tljunit-eclipse/pom.xml#L47
Regards Mirko
--
http://illegalstateexception.blogspot.com/
https://github.com/mfriedenhagen/ (http://osrc.dfm.io/mfriedenhagen)
https://bitbucket.org/mfriedenhagen/
> --
> You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

step...@getkahoot.com

unread,
Dec 18, 2015, 4:57:56 AM12/18/15
to JaCoCo and EclEmma Users, ocat...@gmail.com, gaymailatga...@gmail.com
May I ask which argument you passed and how you passed it ?
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages