java如何使用Arquillian从单独的Maven模块测试战争内容
我在网上找到了一些零碎的知识,但还没能把它们组合起来解决这个具体的问题This answer似乎是一个很好的开始,但它专门处理耳朵依赖
我的(简化的)maven项目结构如下:
parent
|__domain (a jar)
|__domain-it (integration tests for the domain module)
|__web (a war; depends on domain)
|__web-it (integration tests for the web module)
我正在寻找以下问题的解决方案:
- 我想进行Arquillian集成测试,测试
web
模块包含的代码李> - 这些测试将包含在单独的
web-it
模块中李> - 由于
web
模块依赖于domain
模块,因此web-it
集成测试还需要在类路径上包含来自domain
模块的代码李> domain
和web
都依赖于某些第三方库,例如org.apache.commons:commons-lang3
测试类路径上也需要它李>- 这些测试需要在命令行上通过Maven运行,并通过junit直接在Eclipse中运行李>
我正在用Glassfish 3.1.2跑步
任何帮助都将不胜感激。我觉得奇怪的是,这个场景没有特定的Arquillian文档,因为我认为这是一个非常常见的场景。也许我错过了一些基本的东西
以下是我迄今为止尝试过的一些方法:
通过向
web-it/pom.xml
添加以下内容,使web-it
依赖于web
,如下所示:<dependency> <groupId>${project.groupId}</groupId> <artifactId>web</artifactId> <version>${project.version}</version> <scope>test</scope> <type>war</type> </dependency>
但这不包括测试类路径上
web
的任何类通过配置
web
到produce an attached classes jar的war插件,使web-it
依赖于web
的类。在web/pom.xml
中:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <attachClasses>true</attachClasses> </configuration> </plugin>
在
web-it/pom.xml
中:<dependency> <groupId>${project.groupId}</groupId> <artifactId>web</artifactId> <version>${project.version}</version> <scope>test</scope> <classifier>classes</classifier> </dependency>
这包括测试类路径上来自
web
的类,但不包括任何可传递依赖项(例如commons-lang3
)
我也考虑过,但还没有尝试过:
- 使用Maven Warpath plugin,如this answer中所述。但是,在m2e/eclipse中使用它时,似乎存在一些问题,我希望能够从eclipse运行集成测试李>
- 以某种方式使用MavenImporter ShrinkWrap Resolver仅基于项目pom创建Arquillian部署。我不确定这将如何在eclipse中运行(即在maven之外),但这也意味着我需要有效地部署整个战争,而不仅仅是它的一个子集——我喜欢并且希望能够保留Arquillian的一个特性李>
共 (0) 个答案