0 Replies Latest reply on Mar 11, 2014 9:40 AM by Timo Zimmermann

    Arquillian and Jacoco: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

    Timo Zimmermann Newbie

      Hey there,

       

      for our Sonarqube instance, I try to get the code coverage statistics from my arquillian integration tests through maven-jacoco and arquillian-jacoco plugin.

      Running a remote glassfishv4 instance.

       

      I have the following pom:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <project
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
          xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.mycompany.myproject</groupId>
          <artifactId>server-platform-parent</artifactId>
          <version>1.0.0-SNAPSHOT</version>
          <packaging>pom</packaging>
      
          <properties>
              <sonar.plugin.version>4.0</sonar.plugin.version>
      
              <!-- BuildResults URIs-->
              <system-name>server</system-name>
              <buildresults-uri>${buildresults-base-uri}/${system-name}/${buildId}</buildresults-uri>
      
              <glassfish.directory>${env.GLASSFISH_HOME}</glassfish.directory>
              <glassfish.home>${glassfish.directory}/glassfish</glassfish.home>
              <glassfish.user>ourGFuser</glassfish.user>
              <glassfish.passwordfile>${env.GLASSFISH_HOME}/path/to/our/passwordfile.txt</glassfish.passwordfile>
      
              <output.directory>target/classes</output.directory>
              <test.output.directory>target/test-classes</test.output.directory>
          </properties>
      
          <profiles>
              <profile>
                  <id>jenkins</id>
                  <properties>
                      <!-- Mandatory Glassfish properties are explicitly set by Jenkins -->
                      <buildId>${BUILD_ID}-${BUILD_NUMBER}</buildId>
                      <buildresults-base-uri>${PUBLISH_LOC}</buildresults-base-uri>
                  </properties>
              </profile>
              <profile>
                  <id>jacoco</id>
                  <build>
                      <plugins>
                          <plugin>
                              <groupId>org.jacoco</groupId>
                              <artifactId>jacoco-maven-plugin</artifactId>
                              <version>0.6.4.201312101107</version>
                              <executions>
                                  <execution>
                                      <id>default-prepare-agent</id>
                                      <goals>
                                          <goal>prepare-agent</goal>
                                      </goals>                                
                                  </execution>
                                  <execution>
                                      <id>default-report</id>
                                      <phase>prepare-package</phase>
                                      <goals>
                                          <goal>report</goal>
                                      </goals>
                                  </execution>
                                  <execution>
                                      <id>default-report-integration</id>
                                      <phase>prepare-package</phase>
                                      <goals>
                                          <goal>report-integration</goal>
                                      </goals>
                                  </execution>
                              </executions>
                          </plugin>
                      </plugins>
                  </build>
              </profile>
              <profile>
                  <id>remote</id>
                  <activation>
                      <activeByDefault>true</activeByDefault>
                  </activation>
                  <dependencies>
                      <dependency>
                          <groupId>org.jboss.arquillian.container</groupId>
                          <artifactId>arquillian-glassfish-remote-3.1</artifactId>
                          <version>1.0.0.CR4</version>
                          <scope>test</scope>
                      </dependency>
                  </dependencies>
              </profile>
          </profiles>
          <dependencies>
              <!-- GlassFish 4 dependencies -->
              ...
              - Lots of dependencies -
              <dependency>
                  <!-- must be on the classpath -->
                  <groupId>org.jacoco</groupId>
                  <artifactId>org.jacoco.agent</artifactId>
                  <classifier>runtime</classifier>
                  <version>0.6.4.201312101107</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>com.oracle</groupId>
                  <artifactId>ojdbc6</artifactId>
                  <version>11.2.0</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.spec</groupId>
                  <artifactId>jboss-javaee-7.0</artifactId>
                  <version>1.0.0.Beta2</version>
                  <type>pom</type>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.shrinkwrap.resolver</groupId>
                  <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.shrinkwrap.resolver</groupId>
                  <artifactId>shrinkwrap-resolver-depchain</artifactId>
                  <version>2.1.0-alpha-1</version>
                  <type>pom</type>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.junit</groupId>
                  <artifactId>arquillian-junit-container</artifactId>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.extension</groupId>
                  <artifactId>arquillian-jacoco</artifactId>
                  <version>1.0.0.Alpha6</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.protocol</groupId>
                  <artifactId>arquillian-protocol-servlet</artifactId>
                  <version>1.1.2.Final-wildfly-1</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.eu.ingwar.tools</groupId>
                  <artifactId>arquillian-suite-extension</artifactId>
                  <version>1.0.4</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian.extension</groupId>
                  <artifactId>arquillian-persistence-impl</artifactId>
                  <version>1.0.0.Alpha6</version>
                  <scope>test</scope>
              </dependency>
          </dependencies>
          <dependencyManagement>
              <dependencies>
                  <dependency>
                      <groupId>org.jboss.shrinkwrap.resolver</groupId>
                      <artifactId>shrinkwrap-resolver-bom</artifactId>
                      <version>2.1.0-alpha-1</version>
                      <scope>import</scope>
                      <type>pom</type>
                  </dependency>
                  <dependency>
                      <groupId>org.jboss.arquillian</groupId>
                      <artifactId>arquillian-bom</artifactId>
                      <version>1.1.2.Final</version>
                      <scope>import</scope>
                      <type>pom</type>
                  </dependency>
                  <dependency>
                      <groupId>org.jboss.arquillian.extension</groupId>
                      <artifactId>arquillian-transaction-bom</artifactId>
                      <version>1.0.1.Final</version>
                      <scope>import</scope>
                      <type>pom</type>
                  </dependency>
              </dependencies>
          </dependencyManagement>
          <build>
              <sourceDirectory>src</sourceDirectory>
              <outputDirectory>${output.directory}</outputDirectory>
              <testSourceDirectory>test</testSourceDirectory>
              <testOutputDirectory>${test.output.directory}</testOutputDirectory>
              <resources>
                  <resource>
                      <directory>resources</directory>
                  </resource>
              </resources>
              <testResources>
                  <testResource>
                      <directory>probes</directory>
                  </testResource>
              </testResources>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>3.1</version>
                      <configuration>
                          <compilerId>javac</compilerId>
                          <source>1.7</source>
                          <target>1.7</target>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.codehaus.mojo</groupId>
                      <artifactId>build-helper-maven-plugin</artifactId>
                      <version>1.8</version>
                      <executions>
                          <execution>
                              <id>add-source</id>
                              <phase>generate-sources</phase>
                              <goals>
                                  <goal>add-source</goal>
                              </goals>
                              <configuration>
                                  <sources>
                                      <source>src-gen</source>
                                      <source>src-gen-keep</source>
                                      <source>src-jpa</source>
                                  </sources>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-ejb-plugin</artifactId>
                      <version>2.3</version>
                      <configuration>
                          <ejbVersion>3.2</ejbVersion>
                      </configuration>
                  </plugin>
                  <plugin>
                      <artifactId>maven-war-plugin</artifactId>
                      <version>2.4</version>
                      <configuration>
                          <warSourceDirectory>WebContent</warSourceDirectory>
                          <failOnMissingWebXml>false</failOnMissingWebXml>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-ear-plugin</artifactId>
                      <version>2.9</version>
                      <configuration>
                          <version>6</version>
                          <defaultLibBundleDir>lib</defaultLibBundleDir>
                          <fileNameMapping>no-version</fileNameMapping>
                          <generateApplicationXml>false</generateApplicationXml>
                          <earSourceDirectory>EarContent</earSourceDirectory>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-failsafe-plugin</artifactId>
                      <version>2.16</version>
                  </plugin>
              </plugins>
          </build>
      </project>
      

       

      A pom.xml in the corresponding integration test folders looks like:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <project
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
          xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <modelVersion>4.0.0</modelVersion>
          <parent>
              <groupId>server-platform</groupId>
              <artifactId>server.platform.releng</artifactId>
              <version>1.0.0-SNAPSHOT</version>
              <relativePath>..</relativePath>
          </parent>
          <name>Server Platform Integration Tests</name>
          <groupId>server-platform-tests</groupId>
          <artifactId>server.platform.releng.tests</artifactId>
          <version>1.0.0-SNAPSHOT</version>
          <packaging>pom</packaging>
          <profiles>
              <profile>
                  <id>integrate</id>
                  <modules>
                      <module>com.mycompany.myproject.frm.svr.test</module>
                      <module>com.mycompany.myproject.frm.svr.dao.test</module>
                      <module>com.mycompany.myproject.nif.svr.svcs.test</module>
                  </modules>
              </profile>
          </profiles>
          <dependencies>
              <dependency>
                  <groupId>server-platform</groupId>
                  <artifactId>com.mycompany.myproject.frm.svr.ear</artifactId>
                  <type>ear</type>
                  <version>1.0.0-SNAPSHOT</version>
                  <scope>test</scope>
              </dependency>
          </dependencies>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-surefire-plugin</artifactId>
                      <version>2.16</version>
                      <configuration>
                          <skipTests>true</skipTests>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-failsafe-plugin</artifactId>
                      <version>2.16</version>
                      <executions>
                          <execution>
                              <id>integration-test</id>
                              <phase>integration-test</phase>
                              <goals>
                                  <goal>integration-test</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
      </project>
      

       

       

      In the console, when I execute:

      mvn clean -Pintegrate,remote,jacoco install

      The Jacoco reports are created but the integration tests cannot be executed.

       

      I get the following error:

       

      Running com.mycompany.myproject.frm.svr.dao.function.ArisingDaoDtoMappingIT
      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.815 sec <<< FAILURE! - in com.mycompany.myproject.frm.svr.dao.function.ArisingDaoDtoMappingIT
      com.mycompany.myproject.frm.svr.dao.function.ArisingDaoDtoMappingIT  Time elapsed: 0.814 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:366)
          at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
          at java.lang.Class.getDeclaredConstructors0(Native Method)
          at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
          at java.lang.Class.getConstructor0(Class.java:2803)
          at java.lang.Class.getDeclaredConstructor(Class.java:2053)
          at org.jboss.arquillian.core.impl.SecurityActions$1.run(SecurityActions.java:182)
          at org.jboss.arquillian.core.impl.SecurityActions$1.run(SecurityActions.java:179)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.jboss.arquillian.core.impl.SecurityActions.getConstructor(SecurityActions.java:178)
          at org.jboss.arquillian.core.impl.SecurityActions.newInstance(SecurityActions.java:152)
          at org.jboss.arquillian.core.impl.Reflections.createInstance(Reflections.java:122)
          at org.jboss.arquillian.core.impl.ManagerImpl.createExtensions(ManagerImpl.java:410)
          at org.jboss.arquillian.core.impl.ManagerImpl.fireProcessing(ManagerImpl.java:345)
          at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:98)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
          at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:156)
          at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:111)
          at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:97)
          at org.jboss.arquillian.core.spi.ManagerBuilder.create(ManagerBuilder.java:77)
          at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:55)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
          at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156)
          at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
          at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
          at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:93)
          at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
          at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
          at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
      

       

      Without the jacoco profile the integration tests are running. Of course without code coverage.

      mvn clean -Pintegrate,remote install

      I found this question and solution:

      Exception when running tests in Jenkins

       

      But I explicitly activate the profiles when executing the build...

      Can someone help me or give me a hint. I'm kinda stuck right now.

       

      Thanks in advance!

      Timo