1 Reply Latest reply on Mar 28, 2014 10:38 AM by jmkjmk

    How to collect code coverage with Arquillian, Jacoco and Tomcat 7?

    tommysdk

      I've tried getting Arquillian to work with Jacoco to be able to collect integration test code coverage when running in Tomcat 7 but with no luck. The Arquillian tests would not even run without an exception with Jacoco 0.6.x on Arquillian-Jacoco-extension 1.0.0.Alpha5. Tests on Tomcat 7 seems to only run with Jacoco 0.5.x.

       

      What configuration would enable collection of code coverage from Arquillian tests? The tests are executed by the maven failsafe plugin. I'm unable to get an jacoco exec-file for the integration tests. Attached an example project corresponding to my current project setup.

       

      pom.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
          <modelVersion>4.0.0</modelVersion>
      
          <groupId>com.acme</groupId>
          <artifactId>example</artifactId>
          <version>1.0-SNAPSHOT</version>
          <packaging>war</packaging>
        
          <properties>      
              <spring-version>4.0.2.RELEASE</spring-version>
              <junit-version>4.11</junit-version>
              <tomcat7-embedded-version>7.0.30</tomcat7-embedded-version>
              <arquillian-version>1.1.3.Final</arquillian-version>
              <arquillian-spring-version>1.0.0.Beta2</arquillian-spring-version>
          </properties>
      
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-surefire-plugin</artifactId>
                      <version>2.12</version>
                      <configuration>
                          <excludes>
                              <exclude>**/*IntegrationTest*.java</exclude>
                          </excludes>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-failsafe-plugin</artifactId>
                      <version>2.12</version>
                      <executions>
                          <execution>
                              <id>integration-tests</id>
                              <goals>
                                  <goal>integration-test</goal>
                                  <goal>verify</goal>
                              </goals>
                              <configuration>
                                  <skipTests>false</skipTests>
                                  <includes>
                                      <include>**/*IntegrationTest*.java</include>
                                  </includes>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
                  <plugin>
                      <!-- Unit and Integration test coverage -->
                      <groupId>org.jacoco</groupId>
                      <artifactId>jacoco-maven-plugin</artifactId>
                      <version>0.5.10.201208310627</version>
                      <executions>
                          <execution>
                              <id>pre-unit-test</id>
                              <phase>compile</phase>
                              <goals>
                                  <goal>prepare-agent</goal>
                              </goals>
                              <configuration>
                                  <destFile>${project.build.directory}/coverage-reports/jacoco-unit.exec</destFile>
                              </configuration>
                          </execution>
                          <execution>
                              <id>post-unit-test</id>
                              <phase>test</phase>
                              <goals>
                                  <goal>report</goal>
                              </goals>
                              <configuration>
                                  <dataFile>${project.build.directory}/coverage-reports/jacoco-unit.exec</dataFile>
                                  <outputDirectory>${project.reporting.outputDirectory}/jacoco-unit-coverage</outputDirectory>
                              </configuration>
                          </execution>
                          <execution>
                              <id>pre-integration-test</id>
                              <phase>pre-integration-test</phase>
                              <goals>
                                  <goal>prepare-agent</goal>
                              </goals>
                              <configuration>
                                  <destFile>${project.build.directory}/coverage-reports/jacoco-integration.exec</destFile>
                              </configuration>
                          </execution>
                          <execution>
                              <id>post-integration-test</id>
                              <phase>post-integration-test</phase>
                              <goals>
                                  <goal>report</goal>
                              </goals>
                              <configuration>
                                  <dataFile>${project.build.directory}/coverage-reports/jacoco-integration.exec</dataFile>
                                  <outputDirectory>${project.reporting.outputDirectory}/jacoco-integration-coverage</outputDirectory>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
        
          <dependencyManagement>
              <dependencies>
                  <dependency>
                      <groupId>org.jboss.arquillian</groupId>
                      <artifactId>arquillian-bom</artifactId>
                      <version>${arquillian-version}</version>
                      <scope>import</scope>
                      <type>pom</type>
                  </dependency>
              </dependencies>
          </dependencyManagement>
      
          <dependencies>
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-core</artifactId>
                  <version>${spring-version}</version>
              </dependency>
      
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-context</artifactId>
                  <version>${spring-version}</version>
              </dependency>
      
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-web</artifactId>
                  <version>${spring-version}</version>
              </dependency>
      
              <dependency>
                  <groupId>org.glassfish.jersey.core</groupId>
                  <artifactId>jersey-server</artifactId>
                  <version>2.6</version>
              </dependency>
      
              <dependency>
                  <groupId>org.glassfish.jersey.ext</groupId>
                  <artifactId>jersey-spring3</artifactId>
                  <version>2.6</version>
                  <exclusions>
                      <exclusion>
                          <groupId>org.springframework</groupId>
                          <artifactId>spring</artifactId>
                      </exclusion>
                      <exclusion>
                          <groupId>org.springframework</groupId>
                          <artifactId>spring-core</artifactId>
                      </exclusion>
                      <exclusion>
                          <groupId>org.springframework</groupId>
                          <artifactId>spring-web</artifactId>
                      </exclusion>
                      <exclusion>
                          <groupId>org.springframework</groupId>
                          <artifactId>spring-beans</artifactId>
                      </exclusion>
                      <exclusion>
                          <groupId>org.springframework</groupId>
                          <artifactId>spring-context</artifactId>
                      </exclusion>
                  </exclusions>
              </dependency>
      
              <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>${junit-version}</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian</groupId>
                  <artifactId>arquillian-bom</artifactId>
                  <version>${arquillian-version}</version>
                  <scope>test</scope>
                  <type>pom</type>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.junit</groupId>
                  <artifactId>arquillian-junit-container</artifactId>
                  <version>${arquillian-version}</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.protocol</groupId>
                  <artifactId>arquillian-protocol-servlet</artifactId>
                  <version>${arquillian-version}</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.extension</groupId>
                  <artifactId>arquillian-service-integration-spring-inject</artifactId>
                  <version>${arquillian-spring-version}</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.container</groupId>
                  <artifactId>arquillian-tomcat-embedded-7</artifactId>
                  <version>1.0.0.CR6</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.apache.tomcat.embed</groupId>
                  <artifactId>tomcat-embed-core</artifactId>
                  <version>${tomcat7-embedded-version}</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>org.apache.tomcat.embed</groupId>
                  <artifactId>tomcat-embed-jasper</artifactId>
                  <version>${tomcat7-embedded-version}</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>org.apache.tomcat</groupId>
                  <artifactId>tomcat-juli</artifactId>
                  <version>${tomcat7-embedded-version}</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.extension</groupId>
                  <artifactId>arquillian-jacoco</artifactId>
                  <version>1.0.0.Alpha4</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jacoco</groupId>
                  <artifactId>org.jacoco.core</artifactId>
                  <version>0.5.10.201208310627</version>
                  <scope>test</scope>
              </dependency>
          </dependencies>
      
      </project>