因此,我尝试在 Eclipse 上使用 Arquilian 为学校项目测试 maven 项目,但是当我尝试通过
mvn clean test运行测试时,
我得到以下堆栈跟踪:
测试运行:1,失败:0,错误:1,跳过:0,经过的时间:3.361 秒 {"Operation step-1" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\" testCapAnalogique.war\".POST_MODULE" => "WFLYSRV0153:无法处理部署\"testCapAnalogique.war\"的阶段POST_MODULE
原因:java.lang.RuntimeException:WFLYSRV0177:使用服务模块加载器中的模块“deployment.testCapAnalogique.war”的 ClassLoader ModuleClassLoader 获取类 fr.esisar.locVoiture.stateless.CapAnalogiqueStateless 的反射信息时出错
原因:java.lang.NoClassDefFoundError:无法链接 fr/esisar/locVoiture/entities/CapAnalogique(来自服务模块加载器的模块 \"deployment.testCapAnalogique.war\"):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>
以及以下 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>
test-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 的新手,我可能会遗漏一些琐碎的事情。