首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何动态设置嵌入式WildFly服务器进行Maven测试

如何动态设置嵌入式WildFly服务器进行Maven测试
EN

Stack Overflow用户
提问于 2016-11-02 13:00:28
回答 1查看 1.6K关注 0票数 4

我有一个关于如何设置嵌入式Wildfly 10服务器的问题,以便进行集成测试。

代码语言:javascript
复制
<!-- Loading Wildfly 10 on the fly and copy it into the target folder. -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <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>10.0.0.Final</version>
                        <type>zip</type>
                        <overWrite>false</overWrite>
                        <outputDirectory>target</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <version>1.1.0.Alpha1</version>
    <configuration>
        <jbossHome>target/wildfly-10.0.0.Final</jbossHome>
        <hostname>127.0.0.1</hostname>
        <!--  <port>9990</port> -->
        <filename>${project.build.finalName}.war</filename>
        <java-opts>
            <java-opt>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005</java-opt>
        </java-opts>
        <commands>
            <command>/subsystem=logging/file-handler=debug:add(level=DEBUG,autoflush=true,file={"relative-to"=>"jboss.server.log.dir",
                "path"=>"debug.log"})</command>
            <command>/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[debug])</command>
        </commands>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.4</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>deploy</goal>
            </goals>
        </execution>
        <execution>
            <id>start-wildfly</id>
            <phase>test-compile</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
        <execution>
            <id>shutdown-wildfly</id>
            <phase>test</phase>
            <goals>
                <goal>shutdown</goal>
            </goals>
        </execution>
    </executions>
</plugin>

首先,Maven动态下载服务器,将其保存到目标文件夹中。稍后,我想复制一个新的standalone.xml,启动服务器,运行集成测试并停止服务器。

到目前为止,我还没有看到我已经启动了服务器。

代码语言:javascript
复制
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.example.FunctionalTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.071  sec <<< FAILURE! - in com.example.FunctionalTest
basicPingTest(com.example.FunctionalTest)  Time elapsed: 0.07 sec  <<< ERROR!
java.net.ConnectException: Connection refused
at com.example.FunctionalTest.basicPingTest(FunctionalTest.java:39)

Results :

Tests in error: 
 FunctionalTest.basicPingTest:39 » Connect Connection refused

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

有人知道如何设置一个Maven来启动和停止嵌入式Wildfly服务器,启动测试用例,并希望看到一些日志记录吗?

EN

回答 1

Stack Overflow用户

发布于 2016-11-03 21:19:43

我建议看看阿基利安,它将负责容器生命周期管理,并通过将它们部署到容器来运行您的测试。好的一点是,这还允许在IDE中运行测试,因为测试(runner)本身将管理容器生命周期。

当使用WildFly Maven插件控制容器时,Maven故障安全插件应该用于这种集成测试,因为它确保容器在测试执行后也在发生故障时被安全关闭。

您还可以从Hibernate搜索中引入这些集成测试,在那里我们使用Arquillian来运行集成测试。请查看src/test/resources/arquillian.xml,在这里我们指向一些要使用的特定服务器配置文件,而不是standalone.xml。

这个POM还展示了如何在运行测试之前使用Maven依赖插件下载WildFly并提取它。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40380610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档