我如何通过将整个 war 部署到 WildFly embedded 来设置 arquillian 来测试 Maven war 项目?
How do I setup arquillian to test a maven war project by deploying the entire war to WildFly embedded?
我想在嵌入式 WildFly 实例上对我的 war 进行宏观(不是微观!)黑盒测试。
我的 maven 项目是这样的
<project>
...
<packaging>war</packaging>
<!-- Lots of classes in src/main/webapp and files in src/main/webapp -->
<dependencies>
<!-- Lots of compile/runtime dependencies that change very frequently -->
<!-- Lots of test dependencies that change very frequently -->
</dependencies>
</project>
我的 arquillian 测试需要满足以下要求:
- 将整个 war 部署到测试中的应用服务器。这包括所有生产 classes、所有 运行 时间依赖项和所有
src/main/webapp
文件。从维护的角度来看,不可能进行微部署,因为 class 依赖项和 jar 依赖项变化非常频繁。所以我们无法枚举 ShrinkWrap 部署中的任何内容。
- 不要在测试中硬编码任何东西或arquillian.xml专家已经知道的东西
pom.xml
.这包括版本字符串、依赖项列表、包或 class 列表、应用程序服务器安装目录等。
- 不要使用超过 1 个 Maven 模块。我测试 war 的测试属于生成 war.
的同一个 Maven 模块的测试文件夹
- 检查我的代码的用户需要能够如此简单地 运行 测试:
- 测试需要 运行 从 IntelliJ 简单地用 IntelliJ 打开
pom.xml
之后。
- 使用WildFly嵌入式容器,所以不需要先安装任何东西,不需要先安装任何进程运行绝对不需要设置
JBOSS_HOME
环境变量第一。
- 我只对黑盒测试感兴趣,所以我所有的测试都可以运行 as client.
理论上,Arquillian 的 Maven 解析器、嵌入式容器、@RunAsClient
、maven failsafe 插件、一些 arquillian.xml
魔法和许多 maven 魔法都是可能的。但在实践中,我无法让这些东西一起工作,我也找不到任何文档来适当地涵盖这种情况,所以我希望有人能清楚地展示他们如何一起工作。
听起来绝对像是 ShrinkWrap Resolver 的案例Maven Importer (not to be confused with the Maven Resolver). Here 是一些显示其用法的测试。
我有一个独立示例,仅针对 Gradle Importer ( I know you're using maven ), but the test construction is similiar here.
我目前没有一个完整的示例可以公开地与 @RunAsClient
和 Maven Importer 一起使用,但我有一个项目将它们与 Graphene
一起使用,并且这种组合确实有效:)。一般来说,测试应该是这样的:
@RunWith(Arquillian.class)
public class SomeControllerIT {
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(MavenImporter.class).loadPomFromFile("pom.xml").importBuildOutput()
.as(WebArchive.class);
}
@Test
@RunAsClient
public void shouldDoSth() throws Exception {
...
}
}
为什么要使用 Maven Importer 而不是 war 部署? War 是在测试执行后创建的,这意味着如果 war 在测试执行期间存在,那么它来自以前的构建并且已过时。
我想在嵌入式 WildFly 实例上对我的 war 进行宏观(不是微观!)黑盒测试。
我的 maven 项目是这样的
<project>
...
<packaging>war</packaging>
<!-- Lots of classes in src/main/webapp and files in src/main/webapp -->
<dependencies>
<!-- Lots of compile/runtime dependencies that change very frequently -->
<!-- Lots of test dependencies that change very frequently -->
</dependencies>
</project>
我的 arquillian 测试需要满足以下要求:
- 将整个 war 部署到测试中的应用服务器。这包括所有生产 classes、所有 运行 时间依赖项和所有
src/main/webapp
文件。从维护的角度来看,不可能进行微部署,因为 class 依赖项和 jar 依赖项变化非常频繁。所以我们无法枚举 ShrinkWrap 部署中的任何内容。 - 不要在测试中硬编码任何东西或arquillian.xml专家已经知道的东西
pom.xml
.这包括版本字符串、依赖项列表、包或 class 列表、应用程序服务器安装目录等。 - 不要使用超过 1 个 Maven 模块。我测试 war 的测试属于生成 war. 的同一个 Maven 模块的测试文件夹
- 检查我的代码的用户需要能够如此简单地 运行 测试:
- 测试需要 运行 从 IntelliJ 简单地用 IntelliJ 打开
pom.xml
之后。 - 使用WildFly嵌入式容器,所以不需要先安装任何东西,不需要先安装任何进程运行绝对不需要设置
JBOSS_HOME
环境变量第一。
- 测试需要 运行 从 IntelliJ 简单地用 IntelliJ 打开
- 我只对黑盒测试感兴趣,所以我所有的测试都可以运行 as client.
理论上,Arquillian 的 Maven 解析器、嵌入式容器、@RunAsClient
、maven failsafe 插件、一些 arquillian.xml
魔法和许多 maven 魔法都是可能的。但在实践中,我无法让这些东西一起工作,我也找不到任何文档来适当地涵盖这种情况,所以我希望有人能清楚地展示他们如何一起工作。
听起来绝对像是 ShrinkWrap Resolver 的案例Maven Importer (not to be confused with the Maven Resolver). Here 是一些显示其用法的测试。
我有一个独立示例,仅针对 Gradle Importer ( I know you're using maven ), but the test construction is similiar here.
我目前没有一个完整的示例可以公开地与 @RunAsClient
和 Maven Importer 一起使用,但我有一个项目将它们与 Graphene
一起使用,并且这种组合确实有效:)。一般来说,测试应该是这样的:
@RunWith(Arquillian.class)
public class SomeControllerIT {
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(MavenImporter.class).loadPomFromFile("pom.xml").importBuildOutput()
.as(WebArchive.class);
}
@Test
@RunAsClient
public void shouldDoSth() throws Exception {
...
}
}
为什么要使用 Maven Importer 而不是 war 部署? War 是在测试执行后创建的,这意味着如果 war 在测试执行期间存在,那么它来自以前的构建并且已过时。