简体   繁体   English

如何使使用maven-assembly-plugin生成的WAR存档可用于其​​他项目的单元测试?

[英]How do I make a WAR archive produced with maven-assembly-plugin available for other projects' unit tests?

My problem consists of two maven projects, a server project A and a client project B. A uses maven-assembly-plugin to produce several variants of A, where one variant is a WAR archive. 我的问题包括两个Maven项目,一个服务器项目A和一个客户端项目B。A使用maven-assembly-plugin生成A的多个变体,其中一个变体是WAR存档。 The problem I am facing relates to the test-driven development of B; 我面临的问题与B的测试驱动开发有关。 how can I make the WAR archive produced in project A accessible/addressable from unit tests in project B? 如何使项目B中的单元测试可以访问/寻址项目A中产生的WAR归档文件? My idea is to construct test cases in project B where the WAR archive is deployed in an embedded Jetty server through the WebApppContext's setWar(String path) function. 我的想法是在项目B中构造测试用例,在其中通过WebApppContext的setWar(String path)函数将WAR存档部署在嵌入式Jetty服务器中。

You can declare an artifact from the other submodule as a test dependency , eg: 您可以将其他子模块中的工件声明为测试依赖项 ,例如:

<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>ModuleA</artifactId>
        <version>${project.version}</version>
        <type>test-jar</type>
        <scope>test</scope>
    </dependency>

</dependencies>

In this way, you can surely use jars from the other module. 这样,您肯定可以使用其他模块中的jar。 I am not sure if it works for a WAR file though - but it may be worth a try. 我不确定它是否适用于WAR文件-但可能值得一试。

Note that tests run against a WAR deployed in an embedded web container would hardly count as unit tests, rather integration tests. 请注意,针对部署在嵌入式Web容器中的WAR运行的测试几乎不算作单元测试,而是集成测试。 The approach that works in out project is: 在项目中可行的方法是:

  1. build the web app (in our case an EAR) and deploy it (we are using the JBoss Maven plugin, but it could be eg Cargo or others in your case) 构建Web应用程序(在我们的情况下为EAR)并进行部署(我们使用的是JBoss Maven插件,但在您的情况下可能是例如Cargo或其他)
  2. run a separate build (with a specific timeout to allow the server to start up) which executes the integration tests against the deployed web app 运行一个单独的构建(具有特定的超时时间以允许服务器启动),该构建针对已部署的Web应用程序执行集成测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM