首页 文章

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

提问于
浏览
5

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

有没有一套简洁的说明如何在托管Wildfly 8容器上运行Java EE集成测试?

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

  • docs对于嵌入式案例,maven-dependency-plugin的 unpack 目标可用于下载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

    没必要 . 只是不要忘记将Arquillian.xml文件作为pom中的测试资源提供:

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

相关问题