6 Replies Latest reply on Jun 10, 2013 11:19 AM by sursini

    Unable to get Jacoco coverage with Arquillian tests

      I'm managing a multi-module project with module tests implemented with Arquillian.

      The structure of the project is the following

       

       

      Maven Project Structure

      +- Root Pom (root level)

               +- Server 1 (Second level)

                        +-Web service module 1 (Third level)

                        +-EJB module 2

                +- Server 2

                        +-Web service module 1

                        ....

       

      In my root pom.xml we have the following configuration :

       

       

      <project>
          ...
      
          <properties>
              ...
              <jacoco.version>0.6.0.201210061924</jacoco.version>
          </properties>
      
          <profiles>
              <profile>
                  <id>integration-tests</id>
                  <!-- activated only for third level modules -->
                  <activation>
                      <file>
                          <exists>../../pom.xml</exists>
                      </file>
                  </activation>
      
                  <properties>
                      <sonar.jacoco.reportPath>../../target/jacoco.exec
                      </sonar.jacoco.reportPath>
                      <sonar.jacoco.itReportPath>../../target/jacoco-it.exec
                      </sonar.jacoco.itReportPath>
                      <sonar.dynamicAnalysis>reuseReports
                      </sonar.dynamicAnalysis>
                      <sonar.core.codeCoveragePlugin>jacoco
                      </sonar.core.codeCoveragePlugin>
                  </properties>
      
                  <dependencyManagement>
                      <dependencies>
                          <dependency>
                              <groupId>org.jboss.arquillian.extension
                              </groupId>
                              <artifactId>arquillian-jacoco</artifactId>
                              <version>1.0.0.Alpha5</version>
                          </dependency>
      
                          <dependency>
                              <groupId>org.jacoco</groupId>
                              <artifactId>org.jacoco.core</artifactId>
                              <version>${jacoco.version}</version>
                          </dependency>
                      </dependencies>
                  </dependencyManagement>
                  <build>
      
                      <pluginManagement>
                          <plugins>
                              <plugin>
                                  <artifactId>maven-surefire-plugin
                                  </artifactId>
                                  <version>2.14.1</version>
                                  <inherited>true</inherited>
                                  <configuration>
                                      <argLine>${coverageAgent}</argLine>
                                      <enableAssertions>true
                                      </enableAssertions>
                                      <systemPropertyVariables>
                                          <arquillian.launch>jenkins
                                          </arquillian.launch>
                                      </systemPropertyVariables>
                                      <testFailureIgnore>true
                                      </testFailureIgnore>
                                  </configuration>
                              </plugin>
                          </plugins>
                      </pluginManagement>
                      <plugins>
                          <plugin>
                              <groupId>org.jacoco</groupId>
                              <artifactId>jacoco-maven-plugin</artifactId>
                              <version>${jacoco.version}</version>
                              <configuration>
                                  <destFile>${sonar.jacoco.reportPath}
                                  </destFile>
                                  <dataFile>${sonar.jacoco.reportPath}
                                  </dataFile>
                                  <output>file</output>
                                  <append>true</append>
                                  <propertyName>coverageAgent</propertyName>
                              </configuration>
                              <executions>
                                  <execution>
                                      <id>jacoco-prepare</id>
                                      <goals>
                                          <goal>prepare-agent</goal>
                                      </goals>
                                  </execution>
                                  <execution>
                                      <id>jacoco-report</id>
                                      <phase>prepare-package</phase>
                                      <goals>
                                          <goal>report</goal>
                                      </goals>
                                  </execution>
                              </executions>
                          </plugin>
                      </plugins>
                  </build>
              </profile>
          </profiles>
      </project>       
      

       

       

      My arquillian.xml contains the following :

       

       

      <arquillian xmlns="http://jboss.org/schema/arquillian"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
      
          <defaultProtocol type="Servlet 3.0" >
              <property name="executionType">MANAGED</property>
          </defaultProtocol>
      
          <container qualifier="jboss" default="true">
              <configuration>
                  <property name="serverConfig">standalone.xml</property>
                  <property name="allowConnectingToRunningServer">true</property>
              </configuration>
          </container>
      
          <container qualifier="jenkins" default="false">
              <configuration>
                  <property name="serverConfig">standalone.xml</property>
                  <property name="javaVmArguments">-Xms64m -Xmx1024m -XX:MaxPermSize=512m -Djboss.socket.binding.port-offset=8000</property>
                  <property name="allowConnectingToRunningServer">false</property>
                  <property name="managementPort">17999</property>
                  <property name="jbossHome">target/jboss-as-7.1.1.Final</property>
              </configuration>
          </container>    
      
          <extension qualifier="persistence-dbunit">
              <property name="datatypeFactory">org.dbunit.ext.h2.H2DataTypeFactory</property>
          </extension>
      
          <!--  Probably useless -->
          <extension qualifier="jacoco">
              <property name="includes">com.mydomain.*</property>
          </extension>    
      
      </arquillian>
      

       

      When I execute the test (in the following example for one module only) :

       

      mvn test -pl :<third level artifactId>
      

       

      I get the jacoco.exe file created in <root folder>/target/jacoco.exec as expected

       

      But when I try to execute the report using the jacoco-maven-plugin

       

      mvn org.jacoco:jacoco-maven-plugin:0.6.0.201210061924:report -DdataFile="target/jacoco.exec"
      

       

      I got the coverage of the JUnit test but nothing about the Arquillian tests.

       

      I tried to play with the jacoco versions and i used the Servlet 3.0 protocol without success.

       

      Thanks in advance for your help

        • 1. Re: Unable to get Jacoco coverage with Arquillian tests

          I get now the following message from the arquillian persistence module :

           

          WARNING [org.jboss.arquillian.persisten] org.jboss.arquillian.persistence.core.configuration.PersistenceConfiguration@5baa0b72[qualifier=persistence] does not have property named '$jacocoData'. Please revise your arquillian.xml.
          

           

          I tried to enter a value for jacocoData in my arquillian.xml file  :

           

               <extension qualifier="persistence">
                   <property name="jacocoData">C:\var\projects\1.0-SNAPSHOT\swse\target\jacoco.exec</property>
              </extension>
          

           

          with the same result about missing $jacocoData property. I tried with the $ sign :

           

           

               <extension qualifier="persistence">
                   <property name="$jacocoData">C:\var\projects\1.0-SNAPSHOT\swse\target\jacoco.exec</property>
              </extension>
          

           

          As a consequence it crashs arquillian persistence :

           

          com.richemont.catalog.srv.catalog.CatalogServiceTest  Time elapsed: 0.785 sec  <<< ERROR!
          java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
                  at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
                  at java.security.AccessController.doPrivileged(Native Method)
                  at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
                  at java.lang.Class.forName0(Native Method)
                  at java.lang.Class.forName(Class.java:169)
                  at org.jboss.arquillian.persistence.core.configuration.ConfigurationTypeConverter.convert(ConfigurationTypeConverter.java:191)
                  at org.jboss.arquillian.persistence.core.configuration.ConfigurationImporter.createConfiguration(ConfigurationImporter.java:153)
                  at org.jboss.arquillian.persistence.core.configuration.ConfigurationImporter.createFrom(ConfigurationImporter.java:69)
          
          • 2. Re: Unable to get Jacoco coverage with Arquillian tests
            meetoblivion

            Hi Sebastian, is your deployment testable (@Deployment(testable=true) ?)

            • 3. Re: Unable to get Jacoco coverage with Arquillian tests

              Hello John,

              It is not in testable mode. Do you think it could have an impact on Jacoco

              • 4. Re: Unable to get Jacoco coverage with Arquillian tests
                bmajsak

                Hi Sebastien,

                 

                in fact it is in testable mode, but you are not specifying it explicitly (otherwise APE wouldnt work).

                 

                With regards to the exception about $jacocoData, this is bug in APE Alpha6 already fixed in master. I will release Alpha7 this week. Hopefully that would solve the problem you are facing now. You can also try to build snapshot yourself from the git repo to see if that is fixed for your very usecase - https://github.com/arquillian/arquillian-extension-persistence

                • 5. Re: Unable to get Jacoco coverage with Arquillian tests

                  Hi Bartosz,

                  I will build the last version and keep you in touch if it fix my issue

                  • 6. Re: Unable to get Jacoco coverage with Arquillian tests

                    Bartosz,

                    I tried with the snapshot without success but I met a regression with the database seeding :

                     

                     Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.045 sec <<< FAILURE!
                    search_reference_information(com.richemont.catalog.srv.catalog.dao.CatalogDAOTest)  Time elapsed: 0.199 sec  <<< ERROR!
                    org.jboss.arquillian.persistence.dbunit.exception.DBUnitDataSetHandlingException: Failed while seeding database.
                            at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
                            at org.h2.message.DbException.get(DbException.java:169)
                            at org.h2.message.DbException.get(DbException.java:146)
                            at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:81)
                            at org.h2.index.TreeIndex.add(TreeIndex.java:62)
                            at org.h2.table.RegularTable.addRow(RegularTable.java:121)
                            at org.h2.command.dml.Insert.insertRows(Insert.java:124)
                            at org.h2.command.dml.Insert.update(Insert.java:84)
                            at org.h2.command.CommandContainer.update(CommandContainer.java:73)
                            at org.h2.command.Command.executeUpdate(Command.java:219)
                    

                     

                    It seems that the database constraints prevent Arquillian to clean the database.