如何使用 Arquillian 从单独的 Maven 模块测试 WAR 的内容

Rya*_*tts 5 java integration-testing maven jboss-arquillian

我在网上找到了一些零碎的知识,但无法将它们组合起来来解决这个具体案例。这个答案似乎是一个很好的开始,但它专门处理 EAR 依赖关系。

我的(简化的)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)
Run Code Online (Sandbox Code Playgroud)

我正在寻找以下问题的解决方案:

  1. 我想要进行 Arquillian 集成测试来测试模块包含的代码web
  2. 这些测试将包含在一个单独的web-it模块中。
  3. 由于web模块依赖于domain模块,web-it因此集成测试还需要将domain模块中的代码放在类路径上。
  4. 两者domainweb依赖于一些第三方库,例如 org.apache.commons:commons-lang3测试类路径上也需要这些库。
  5. 测试需要通过命令行上的 Maven 运行,并通过 junit 直接在 Eclipse 中运行。

我正在 Glassfish 3.1.2 上运行。

任何帮助,将不胜感激。对我来说很奇怪的是,没有针对这种情况的具体 Arquillian 文档,因为我认为这是一种非常常见的情况。也许我错过了一些基本的东西?

以下是我迄今为止尝试过的一些方法:

  1. 通过添加以下内容来建立web-it依赖,如下所示:webweb-it/pom.xml

    <dependency>  
        <groupId>${project.groupId}</groupId>
        <artifactId>web</artifactId>
        <version>${project.version}</version>
        <scope>test</scope>
        <type>war</type>
    </dependency>
    
    Run Code Online (Sandbox Code Playgroud)

    但这不会包括web测试类路径上的任何类

  2. 通过配置 的 war 插件来生成依赖web-it于 的类,以生成附加的类 jar。在:webwebweb/pom.xml

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <attachClasses>true</attachClasses>
        </configuration>
    </plugin>
    
    Run Code Online (Sandbox Code Playgroud)

    web-it/pom.xml

    <dependency>  
        <groupId>${project.groupId}</groupId>
        <artifactId>web</artifactId>
        <version>${project.version}</version>
        <scope>test</scope>
        <classifier>classes</classifier>
    </dependency>
    
    Run Code Online (Sandbox Code Playgroud)

    这包括测试类路径上的类web,但不包括传递依赖项(例如commons-lang3)。

我也考虑过,但尚未尝试:

  1. 使用Maven Warpath 插件,如本答案所述。不过,当与 m2e/eclipse 一起使用时似乎存在一些问题,并且我希望能够从 eclipse 运行我的集成测试。
  2. 使用MavenImporter ShrinkWrap Resolver以某种方式根据项目 pom.xml 创建一个 Arquillian 部署。我不确定这将如何在 eclipse 中运行(即在 maven 之外),但这也意味着我需要有效地部署整个 WAR,而不仅仅是它的一个子集 - 这是我喜欢并且想要的 Arquillian 功能能够保存。