[英]How to run tests from parent mvn module?
我在mvn中有以下結構。
| pom.xml (parent)
|
|
+----- module A (common classes)
| | pom.xml
| |
| \---src
| +---main
| |
| \---test
| +---junit
| |
| \---integration
|
+----- module B (web app)
| | pom.xml
| |
| \---src
| +---main
|
+----- module C (web app)
| | pom.xml
| |
| \---src
| +---main
模塊A是由所有后續模塊(B,C,...)繼承的模塊。 該模塊具有通用功能和junit /集成測試用例。 它不是一個網絡應用程序。
模塊B是一個Web應用程序。 它依賴於模塊B.
模塊C是一個Web應用程序。 它依賴於模塊B.
我們的Jersey rest / api代碼存在於模塊A中。這樣,無論我們部署什么模塊,我們總是可以訪問rest / api。
到目前為止,我已經設法在模塊C中配置Maven FailSafe插件,以便在運行top(父)pom.xml(即:mvn verify)時站起來一個tomcat實例。
但是,模塊C無法看到模塊A的集成測試。我已嘗試配置maven-jar-plugin( http://maven.apache.org/guides/mini/guide-attached-tests.html )。
在模塊AI的pom.xml中有:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
在模塊CI中有:
<dependency>
<groupId>groupId</groupId>
<artifactId>SCCommon</artifactId>
<type>test-jar</type>
<classifier>tests</classifier>
<version>9.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
當mvn運行Module C failafe插件時,任何人都可以幫我弄清楚如何在Modula A中運行這些集成測試。
注意:集成測試被命名為* IT.java,因此它被故障安全插件獲取。
有沒有其他方法這樣做或甚至使用正確的插件?
非常感謝提前。
如果模塊C包含對帶有測試類文件的 A的依賴關系,則可以在maven-failsafe-plugin(自2.15)配置的<dependenciesToScan>
屬性中引用該依賴關系。
http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#dependenciesToScan
<dependency>
<groupId>com.group</groupId>
<artifactId>A</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>tests</classifier>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>it</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<dependenciesToScan>
<dependency>com.group:A</dependency>
</dependenciesToScan>
</configuration>
</plugin>
使用你的maven-jar-plugin配置我得到了一個空的測試檔案。 我不得不將模式更改為<include>**/*IT.class</include>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.