Here is the process of enabling code coverage analysis for
integration tests by Arquilian and Jacoco. My assumeption is using
Maven as the build tool. When using the Arquilian as integration
testing framework for Java EE in container, the only choose for
code coverage is jacoco. Arquilian has an extension for Jacoco. Our
final setup for using Jacoco with arquilian on WAS and Glassfish
are as folowing:
Jacoco can be used in 2 ways. When building the source by maven
or when running the test in JUnit on IDE (Eclipse)
Maven configuration part
To configure the maven project and enable code coverage for all
integration tests after building the codes by maven all you have to
do is to add two dependencies and declare one plugin to one of the
existing build profiles(or creating a new profile for Jacoco)
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-jacoco</artifactId>
<version>1.0.0.Alpha6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>0.6.4.201312101107</version>
<scope>test</scope>
</dependency>
and the
plugin part:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.0.201403182114</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
When you want to run code coverage after build don't
forget to not skip test in maven:
<properties>
<maven.test.skip>false</maven.test.skip>
</properties>
Other POM configs for reference and compare( an EJB JPA module)
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>2.0.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.0.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
<!--WAS spesific Dependecy for Using arquilian on WAS-->
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-was-remote-8</artifactId>
<version>1.0.0.Final</version>
</dependency>
<!--End Of WAS spesific Dependecy for Using arquilian on WAS-->
<!--GlassFish spesific Dependecy for Using arquilian on GF-->
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-remote-3.1</artifactId>
<version>1.0.0.CR4</version>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<!--End Of GlassFish spesific Dependecy for Using arquilian on GF-->
<build>
<plugins>
<!-- Plugin for CodeCoverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.0.201403182114</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- END OF Plugin for CodeCoverage -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<generatedTestSourcesDirectory>true</generatedTestSourcesDirectory>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
Run in IDE

For using Jacoco in IDE you need EclEmma plugin for Eclipse.
After installing the Plugin all the configs above you can run
code coverage by right click on the test method(class, package,
project) and select Coverage As.
Multi module projects
Issues
Problem with aspect J
References:
comment here
-
http://www.softwarepassion.com/it-coverage-with-arquillian-jacoco-extension/
-
https://community.jboss.org/thread/222403?tstart=0&_sscc=t