如何在特定模块中运行单独的文件夹?
我的模块:
<modules>
<module>common</module>
<module>foo</module>
<module>bar</module>
</modules>
每个模块都有一个2-3测试文件夹。我需要在模块栏中运行测试文件夹“utils”。
我确实限制了团队“MVN测试”:
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/utils/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>surefire-itest</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/utils/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
mvn test - 运行除“utils”之外的所有测试。 mvn integration-test - 运行所有测试。
现在我只需要启动“utils”。我该如何解决这个问题?
答案 0 :(得分:0)
选项一是使用various profiles通过mvn test
运行不同的万不得不执行(以及不同的包含和排除)。
选项二是将failsafe plugin与mvn verify
一起使用。这使得仅运行单元测试或单元测试和集成测试变得容易;只运行集成测试是可能的,但很难。
请勿在{{1}}下使用surefire插件。通常最好不要使用mvn integration-test
。有关原因,请参阅introduction to the maven lifecycle。
答案 1 :(得分:0)
为utils中的测试创建另一个,并将其绑定到要运行它们的阶段。
如果您使用的是JUnit,也可以使用categories对测试进行分组。
答案 2 :(得分:0)
我找到了解决这个问题的方法:
mvn test - 运行除“utils”之外的所有测试 mvn test -P utilsTest - 仅运行测试“utils”
<profiles>
<profile>
<id>utilsTest</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<exclude>none</exclude>
<includes>
<include>**/utils/**</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/utils/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>