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

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

所以我正在尝试在 Eclipse 上使用 Arquilian 为一个学校项目测试一个 Maven 项目,但是当我尝试 运行 通过

mvn clean test 进行测试时

我得到以下堆栈跟踪:

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

我正在使用以下 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>

和下面的测试-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>

和测试-ds.xml如下:

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

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>

请注意,我是 Maven 和 arquillian 的新手,我可能遗漏了一些微不足道的东西。

所以问题是我在我的 createArchiveTest() 函数中添加了 classes 作为 ShrinkWrap create 方法中的资源,它扩展并实现了其他 classes 和接口。事实证明,所有这些实际上都需要作为资源传递。 假设你想测试一个名为 StudentA 的 class,但是这个 class 扩展了另一个名为 Student 的 class 并且 Student class 实现了一个 Person 接口,所有三个都需要传递为资源。