JUnit/Arquillian: 运行托管的Wildfly 8.1容器

5

我正在尝试运行一个简单的测试案例:

有没有一个干净的指令集,告诉我如何在管理的Wildfly 8容器上运行Java EE集成测试?

  • 我只想通过mvn test在一个新下载的Wildfly容器中运行一个简单的测试案例。

  • 文档说对于嵌入式情况,可以使用maven-dependency-pluginunpack目标自动下载并解压Wildfly。

  • 我想要将容器设置为管理状态,以确保测试案例拥有一个由Arquillian本身管理的独立JVM。

现在我该在哪里引用Wildfly文件夹?

1) 我可以通过我的test/resource/arquillian.xml来实现:

<container qualifier="arquillian-wildfly8-managed" default="true">
    <configuration>
        <property name="jbossHome">target/wildfly-8.1.0.Final</property>
        <property name="modulePath">target/wildfly-8.1.0.Final/modules</property>
    </configuration>
</container>

2) 另一种方法是在pom文件中配置surefire-plugin的系统属性:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>2.17</version>
   <configuration>
    <property>
        <name>jboss.home</name>
        <value>${project.basedir}/target/wildfly-8.1.0.Final</value>
    </property>
    <property>
        <name>module.path</name>
        <value>${project.basedir}/target/wildfly-8.1.0.Final/modules</value>
    </property>
</systemProperties> </configuration> </plugin>

现在,当我尝试运行测试时,会显示一个错误:
[ERROR]
/home/me/playground/arquillian-tutorial/src/test/java/org/arquillian/example/ATest.java:[3,19]
error: package javax.inject does not exist

我需要翻译的内容是:“即类找不到。”

我的pom文件摘录如下:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
        </plugin>
    </plugins>
</build>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <version>1.1.5.Final</version>
            <artifactId>arquillian-bom</artifactId>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <!-- <version>1.1.5.Final</version> -->
        <scope>test</scope>
    </dependency>
</dependencies>

    <profile>
        <id>arquillian-wildfly8-managed</id>
        <dependencies>
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-6.0</artifactId>
                <version>3.0.1.Final</version>
                <type>pom</type>
                <scope>test</scope>
            </dependency>
            <!-- Required by jboss-javaee-6.0:3.0.2.Final (https://issues.jboss.org/browse/JBBUILD-708) -->
            <dependency>
                <groupId>xalan</groupId>
                <artifactId>xalan</artifactId>
                <version>2.7.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-arquillian-container-managed</artifactId>
                <version>8.1.0.Final</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <!-- You need the maven dependency plugin to download locally a zip 
                            with the server, unless you provide your own, it will download under the 
                            /target directory -->
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.8</version>
                        <executions>
                            <execution>
                                <id>unpack</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>org.wildfly</groupId>
                                            <artifactId>wildfly-dist</artifactId>
                                            <version>8.1.0.Final</version>
                                            <type>zip</type>
                                            <overWrite>false</overWrite>
                                            <outputDirectory>target</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>

我很困惑。我找不到一个简单的设置,以适当的方式通过Arquillian / Wildfly运行测试用例。你有任何想法、提示或链接吗?
1个回答

0

我强烈建议不要自动下载包含服务器的.zip文件,而是提供自己的服务器实例。

我可以在我的test/resource/arquillian.xml中完成它

是的,这就是做法。

另一种方法是配置surefire-plugin的

不需要。只需不要忘记在pom中将Arquillian.xml文件作为测试资源提供即可:

<testResources>
     <testResource>
           <directory>path/to/resources</directory>
     </testResource>

你能发布一下你的测试用例代码吗?我很想看看你的@Deployment方法。
你的测试中缺少EE实现依赖。
<dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-7.0</artifactId>
                    <version>1.0.0.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                </dependency>

非常感谢您的提示。因此,我理解服务器不应该位于repos / target目录中,而应该放在其他任何地方,对吗?我将立即测试您的提示,非常感谢! - John Rumpel
是的,不在存储库中。 - ra2085
非常感谢你的提示。我决定跳过嵌入式容器实现并尝试管理/远程容器。但它并没有真正起作用,无法连接。你或其他人可能有一个针对使用WildFly管理容器的Arquillian链接的完整工作示例吗? - John Rumpel
你能否更新你的问题,包括已经进行的更改和新的结果/错误?这里有一个非常好的示例,介绍了如何使用Arquillian设置WildFly。它几乎包含了你从一开始就一直在做的事情。http://blog.progs.be/585/wildfly-integration-arquillian-maven - ra2085
5
我强烈建议不要自动下载包含服务器的.zip文件,而是提供自己的服务器实例。@ra2085,我不明白,这样Maven项目如何具备可移植性? - Rade_303

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接