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

问题描述 投票:5回答:1

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

Is there anywhere a clean set of instructions how to run Java EE integration tests on managed Wildfly 8 containers?

  • 我只想在一个新的,下载的Wildfly容器中通过mvn test运行一个简单的测试用例。
  • docs对嵌入式案例说,maven-dependency-plugin的unpack目标可用于下载Wildfly并自动解压缩。
  • 我希望管理容器以确保为Arquillian本身管理的测试用例提供单独的JVM。

Now where do I have to reference the Wildfly folder?

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>

Now, when I'm trying to run the test, an error is shown:

[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运行测试用例。你有任何想法,提示或链接吗?

java-ee junit wildfly jboss-arquillian
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>
© www.soinside.com 2019 - 2024. All rights reserved.