13 Replies Latest reply on Apr 25, 2012 8:32 AM by zebut

    @RunWith(Arquillian.class) fail

    zebut

      Hi,

       

      I'm trying to run tests with arquillian but without success.

      I have an exception when tests run :

       

      Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

      I've seen these topics on the forum but my problem has not been resolved.

       

      I need your help,

       

      Here is my 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/xsd/maven-4.0.0.xsd">

          <modelVersion>4.0.0</modelVersion>

       

          <parent>

              <groupId>org.monGroupId</groupId>

              <artifactId>threejs</artifactId>

              <version>2.x-SNAPSHOT</version>

          </parent>

       

          <!-- =========================================================== -->

          <!--     Module Description                                                                                       -->

          <!-- =========================================================== -->

          <groupId>org.monGroupId</groupId>

          <artifactId>test-threecomponent</artifactId>

          <packaging>war</packaging>

          <name>arquilliam tests</name>

          <description>Test threecomponent component using arquilliam.</description>

       

          <properties>

              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

          </properties>

       

          <dependencyManagement>

              <dependencies>

                  <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>

       

       

          <build>

              <plugins>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-compiler-plugin</artifactId>

                      <version>2.3.2</version>

                      <configuration>

                          <source>1.6</source>

                          <target>1.6</target>

                      </configuration>

                  </plugin>

              </plugins>

          </build>

       

          <dependencies>

              <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>

              <dependency>

                  <groupId>junit</groupId>

                  <artifactId>junit</artifactId>

                  <version>4.8.1</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.junit</groupId>

                  <artifactId>arquillian-junit-container</artifactId>

                  <scope>test</scope>

              </dependency>

          </dependencies>

       

      </project>

       

       

       

       

      Here the exception :

       

      -------------------------------------------------------------------------------

      Test set: org.mapfaces.test.PersonTest

      -------------------------------------------------------------------------------

      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.379 sec <<< FAILURE!

      org.monGroupId.test.PersonTest  Time elapsed: 0.379 sec  <<< ERROR!

      java.lang.RuntimeException: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.

                at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:170)

                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:236)

                at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134)

                at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)

                at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)

                at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)

                at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)

                at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)

      Caused by: java.lang.reflect.InvocationTargetException

                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

                at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

                at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:166)

                ... 14 more

       

       

       

       

       

      A simple class to test :

       

      public class Person {

          private String name;

       

          public Person(String name) {

              this.name = name;

          }

       

          public String getName() {

              return name;

          }

       

          public void setName(String name) {

              this.name = name;

          }

      }

       

       

       

       

      And the tests:

       

      import javax.inject.Inject;

      import junit.framework.Assert;

      import org.jboss.arquillian.container.test.api.Deployment;

      import org.jboss.arquillian.junit.Arquillian;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.jboss.shrinkwrap.api.asset.EmptyAsset;

      import org.jboss.shrinkwrap.api.spec.JavaArchive;

      import org.junit.Test;

      import org.junit.runner.RunWith;

       

      /**

      * Class test

      * Not implemented yet

      */

      @RunWith(Arquillian.class)

      public class PersonTest {

       

          @Deployment

          public static JavaArchive createDeployment() {

              return ShrinkWrap.create(JavaArchive.class)

                  .addClass(Person.class)

                  .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

          }

       

          @Inject

          Person greeter;

       

          @Test

          public void getName() {

              System.out.println("getName");

              String result = "test";

              greeter = new Person(result);

              Assert.assertEquals(result, greeter.getName());

          }

      }

       

      Thank you in advance!

        • 1. Re: @RunWith(Arquillian.class) fail
          vineet.reynolds

          Your project POM doesnt seem to contain a dependency for a container adapter. You'll need to choose one of the supported container adapters in Arquillian, for the archive to be deployed to.

           

          You can refer to this page in the reference guide for the Maven artifact Id of a container adapter that you wish to use.

          • 2. Re: @RunWith(Arquillian.class) fail
            b69

            try to add

             

            <dependency>

                <groupId>org.jboss.as</groupId>

                <artifactId>jboss-as-arquillian-container-managed</artifactId>

                <version>7.1.1.Final</version

                <scope>provided</scope>

            </dependency>

             

            to your pom if working with jboss-as! should work.

            • 3. Re: @RunWith(Arquillian.class) fail
              zebut

              Thanks for your answers,

               

              I try to add container to my pom.xml (adding the following code below </dependencies> tag)

               

                  <profiles>

                      <profile>

                          <id>jbossas-managed-7</id>

                          <activation>

                              <activeByDefault>true</activeByDefault>

                          </activation>

                          <dependencies>

                              <dependency>

                                  <groupId>org.jboss.as</groupId>

                                  <artifactId>jboss-as-arquillian-container-managed</artifactId>

                                  <version>7.1.1.Final</version>

                                  <scope>provided</scope>

                              </dependency>

                          </dependencies>

                      </profile>

                  </profiles>

               

               

               

               

              I have the same problems :

              Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

               

              but now I have warnings :

               

              log4j:WARN No appenders could be found for logger (org.jboss.logging).

              log4j:WARN Please initialize the log4j system properly.

              Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.279 sec <<< FAILURE!

              • 4. Re: @RunWith(Arquillian.class) fail
                b69

                Have you declared the system variable JBOSS_HOME? You should either declare this environment variable to point to the installation directory of your AS like D:\programs\jbossAS7.1.2.SNAPSHOT or create an arquillian.xml within the src/test/resources folder with the content:

                 

                <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"
                >
                   
                <container qualifier="jbossas-7-managed" default="true">
                       
                <configuration>
                           
                <property name="jbossHome">directory of jboss-as installation</property>
                       
                </configuration>
                   
                </container>
                </arquillian>

                 

                The warnings can safely be ignored, at least while standard formatting of log output is good enough.

                 

                If it still doesn't work, You may try to follow the guide:

                http://arquillian.org/guides/getting_started/#open_the_project_in_eclipse

                 

                This gives you quickly a running example which allows you to isolate your problem by comparision.

                • 5. Re: @RunWith(Arquillian.class) fail
                  zebut

                  I have to install JBOSS-AS on my computer ?

                  Do I not have it with maven dependencies?

                  • 6. Re: @RunWith(Arquillian.class) fail
                    b69

                    For the managed version yes, you must install it on your computer!

                    As far as I know even the embedded version is making referencies to the AS directory. I'm not sure what all is included in the maven dependencies w.r.t the embedded testing.

                    Until now I never used the embedded version, because it referencies AS6 which I don't have installed. Maybe I must try once to see what is happening.

                    1 of 1 people found this helpful
                    • 7. Re: @RunWith(Arquillian.class) fail
                      zebut

                      Okay, thank you for your answers.

                      I thought use Arquillian without installing anything on the computer.

                      • 8. Re: @RunWith(Arquillian.class) fail
                        aslak

                        You can have Maven install it for you, by using the maven-dependency-plugin

                         

                        https://github.com/arquillian/arquillian-showcase/blob/master/servlet/pom.xml#L40

                        1 of 1 people found this helpful
                        • 9. Re: @RunWith(Arquillian.class) fail
                          zebut

                          I tried to add your pom.xml.

                           

                          My problem does not seem to come from dependency :

                          I have the same error that at the beginning : Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

                           

                          Do you have other ideas of where my problem may come from ?

                           

                          I followed the toturial 'getting started' with you pom.xml from my last test.

                           

                          I use

                          Apache Maven 3.0.4

                          Java version: 1.6.0_30, vendor: Sun Microsystems Inc.

                          Java home: /usr/lib/jvm/jdk1.6.0_30/jre

                          OS name: "linux", version: "3.0.0-17-generic", arch: "amd64", family: "unix"

                           

                          thanks by advance

                          • 10. Re: @RunWith(Arquillian.class) fail
                            aslak

                            You don't have the cause for the cause of the exception? The real cause seems to be missing from your stacktrace. Normally when it fails at that point, it's missing 'something' on classpath.

                             

                            One option is that something has been downloaded wrong, maybe try cleaning org.jboss.arquillian.* in your local maven repository.

                            • 11. Re: @RunWith(Arquillian.class) fail
                              zebut

                              I was indeed a conflict between an old version of Arquillian and one I use now.

                              I had a parent project to maven who had old dependencies of Arquillian.

                               

                              I did not have access to this project.

                              Not easy to find the problem .

                               

                              Now I have

                              org.jboss.arquillian.container.spi.ConfigurationException: jbossHome 'null' must exist

                               

                              It is normal with a remote version ?

                               

                              Thank for your help.


                              • 12. Re: @RunWith(Arquillian.class) fail
                                aslak

                                You're using the jboss-as-managed contianer and not the jboss-as-remote container. The difference is the managed require jbossHome set in arquillian.xml to know how to start it. But if you start it your self outside the test and use the remote container, you don't need jbossHome.

                                 

                                 

                                https://docs.jboss.org/author/display/ARQ/Container+configuration

                                 

                                https://docs.jboss.org/author/display/ARQ/JBoss+AS+7.0+-+Remote

                                https://docs.jboss.org/author/display/ARQ/JBoss+AS+7.0+-+Managed

                                • 13. Re: @RunWith(Arquillian.class) fail
                                  zebut

                                  It work perfectly.

                                  Thank you