有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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)

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

  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/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的任何类

  2. 通过配置webproduce 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

我也考虑过,但还没有尝试过:

  1. 使用Maven Warpath plugin,如this answer中所述。但是,在m2e/eclipse中使用它时,似乎存在一些问题,我希望能够从eclipse运行集成测试
  2. 以某种方式使用MavenImporter ShrinkWrap Resolver仅基于项目pom创建Arquillian部署。我不确定这将如何在eclipse中运行(即在maven之外),但这也意味着我需要有效地部署整个战争,而不仅仅是它的一个子集——我喜欢并且希望能够保留Arquillian的一个特性

共 (0) 个答案