eclipsemavenm2eclipsejboss-arquillian

Caused by: java.lang.NoClassDefFoundError: Failed to link when running JUnit tests through Arquilliqn for a Maven project


So I'm trying to test a maven project using Arquilian on Eclipse for a school project, however when I try to run the test through

mvn clean test

I get the following stacktrace:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.361 sec  {"Operation step-1" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"testCapAnalogique.war\".POST_MODULE" => "WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"testCapAnalogique.war\"
    Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class fr.esisar.locVoiture.stateless.CapAnalogiqueStateless with ClassLoader ModuleClassLoader for Module \"deployment.testCapAnalogique.war\" from Service Module Loader
    Caused by: java.lang.NoClassDefFoundError: Failed to link fr/esisar/locVoiture/entities/CapAnalogique (Module \"deployment.testCapAnalogique.war\" from Service Module Loader): fr/esisar/locVoiture/entities/Capteur"}}}}

I'm using the following arquillian.xml:

<?xml version="1.0" encoding="UTF-8"?>
 <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" />

   <container qualifier="jboss" default="true"> 
     <configuration>
        <property name="jbossHome">home/user/CS513-Archive/wildfly- 
                 16.0.0.Final</property>
     </configuration>

 </container> 

</arquillian>

And the following test-persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="test">
        <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <property name="hibernate.show_sql" value="true"/>
        </properties>
    </persistence-unit>

</persistence>

and the test-ds.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
   <!-- The datasource is bound into JNDI at this location. We reference 
      this in META-INF/test-persistence.xml -->
   <datasource jndi-name="java:jboss/datasources/BeanValidationQuickstartTestDS"
      pool-name="bean-validation-quickstart-test" enabled="true"
      use-java-context="true">
      <connection-url>jdbc:h2:mem:bean-validation-quickstart-test;DB_CLOSE_DELAY=-1</connection-url>
      <driver>h2</driver>
     <security>
         <user-name>sa</user-name>
         <password>sa</password>
      </security>

   </datasource>

with the dependencies in pom.xml:


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <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.protocol</groupId>
            <artifactId>arquillian-protocol-servlet</artifactId>
            <scope>test</scope>
        </dependency>


    </dependencies>
        <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.1.13.Final</version>
                <scope>import</scope>
                <type>pom</type>
          </dependency>     
        </dependencies>
     </dependencyManagement>
    <profiles>
        <profile>
            <id>arq-managed</id>
                <dependencies>
                    <dependency>
                        <groupId>org.wildfly.arquillian</groupId>
                        <artifactId>wildfly-arquillian-container-managed</artifactId>
                        <version>2.1.0.Final</version>
                        <scope>test</scope>
                    </dependency>
                </dependencies>
        </profile>

        <profile>
            <id>arq-remote</id>
            <activation>
                    <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.wildfly.arquillian</groupId>
                    <artifactId>wildfly-arquillian-container-remote</artifactId>
                    <version>2.1.0.Final</version>
                    <scope>test</scope>
                </dependency>           
            </dependencies>
        </profile>  
    </profiles>

Please note I'm new to Maven and arquillian and I may be missing something trivial.


Solution

  • So the problem was that I'm adding classes in my createArchiveTest() function as resources in the ShrinkWrap create method, that extend and implement other classes and interfaces. Turns out all of them actually need to be passed as resources. Say you want to test a class called StudentA, but this class extends another class called Student and the Student class implements a Person interface, all three need to be passed as resources.