我有一個包含單元和集成測試的項目。 這些測試已經分解爲單元測試和集成測試,同時使用不同的套件作爲套件。用於將測試分離爲單元和集成測試的Maven surefire配置失敗
如何配置surefire在階段「集成測試」的階段「測試」和集成測試期間執行單元測試。
這裏是我當前的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*Test*.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>unit-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/CoreUnitTests.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/CoreIntegrationTests.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
利用這種結構沒有測試將被執行,但如果我刪除了「不包括」所有測試階段中的「測試」,而不僅是單元測試執行。
更新 - 解決方案
與亞當·米哈利克的解釋,我是能夠解決的問題。 而是覆蓋默認測試我跳過這些測試,因爲ID「單元測試」比「默認測試」我的單元測試 這裏更好的是POM的最終配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>default-test</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>unit-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/CoreUnitTests.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/CoreIntegrationTests.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
謝謝你的好解釋和你的解決方案! –