我们正在尝试使用 TestNG 框架在嵌入式 tomcat 容器上运行基于 Spring 的代码的集成测试。
我们尝试使用现有的 Arquillian Spring Extension,但没有取得多大成功。也许一些缺少的配置。我们已按照此帖子的说明进行操作
我们的 pom 包含以下依赖项:
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.2.Final</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<version>1.0.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<!-- Spring Extension -->
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-service-container-spring</artifactId>
<version>1.0.0.Beta1</version>
<scope>test</scope>
</dependency>
<!-- testing END -->
我们还在我们的 pom.xml 中添加了一个 Tomcat 嵌入式配置文件。
<profile>
<id>arquillian-tomcat-embedded-7</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-7</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>7.0.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>7.0.30</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>3.7</version>
<scope>test</scope>
</dependency>
<!-- Weld servlet for testing CDI injections -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>1.1.9.Final</version>
</dependency>
</dependencies>
</profile>
我们的arquillian.xml
样子...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="tomcat" default="true">
<configuration>
<property name="unpackArchive">true</property>
</configuration>
</container>
我们还尝试将以下几行添加到我们的arquillian.xml
<extension qualifier="spring">
<property name="autoPackage">true</property>
<property name="springVersion">3.0.0.RELEASE</property>
<property name="cglibVersion">2.2</property>
<property name="includeSnowdrop">true</property>
<property name="snowdropVersion">2.0.3.Final</property>
<property name="customContextClass">org.jboss.spring.vfs.context.VFSClassPathXmlApplicationContext</property>
</extension>
我们创建了一个空测试并检查嵌入式 Tomcat 是否启动并且测试是否运行。下一步是验证 Arquillian Spring Extension 是否正常工作,为此我们尝试将 Spring bean 注入到我们的测试中。
问题是@SpringConfiguration
注释根本不可用。所以我们猜测我们缺少一些配置。关于如何进行的任何线索?