我们正在尝试使用TestNG框架在嵌入式tomcat容器上运行基于Spring的代码的集成测试。
我们尝试使用现有的Arquillian Spring Extension但没有取得多大成功。也许有些缺少配置。我们已经关注instructions from this post
我们的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中添加了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
注释根本不可用。所以我们猜测我们缺少一些配置。关于如何进行的任何线索?
答案 0 :(得分:3)
您正在使用arquillian-service-container-spring工件,它是Embedded Spring容器。要使用if与另一个Container,您需要使用arquillian-service-deployer-spring-3和arquillian-service-integration-spring-inject工件。
service-deployer为部署添加了自动添加Spring依赖项,而service-integration-spring-inject在测试用例中添加了@Inject / @ Autowire支持。
请参阅https://github.com/arquillian/arquillian-showcase/blob/master/spring/spring-inject/pom.xml#L43
可在此处找到多个其他示例: https://github.com/arquillian/arquillian-showcase/tree/master/spring