Java 如何运行单独的测试?
如何在特定模块中运行包含测试的单独文件夹 我的模块:Java 如何运行单独的测试?,java,maven,Java,Maven,如何在特定模块中运行包含测试的单独文件夹 我的模块: <modules> <module>common</module> <module>foo</module> <module>bar</module> </modules> 常见的 福 酒吧 每个模块都有一个2-3个测试文件夹。我需要运行模块栏中的测试文件夹“utils” 我没有限制团队
<modules>
<module>common</module>
<module>foo</module>
<module>bar</module>
</modules>
常见的
福
酒吧
每个模块都有一个2-3个测试文件夹。我需要运行模块栏中的测试文件夹“utils”
我没有限制团队“MVN测试”:
maven surefire插件
**/乌提尔斯/**
万无一失
集成测试
测验
没有一个
**/乌提尔斯/**
mvn测试-运行除“utils”之外的所有测试。
mvn集成测试-运行所有测试
现在我只需要开始“utils”。如何解决此问题?选项一是通过mvn测试运行不同的surefire执行(以及不同的包含和排除)
选项二是与mvn验证一起使用。这使得只运行单元测试或单元测试和集成测试变得容易;只运行集成测试是可能的,但很尴尬
不要将surefire插件与mvn集成测试一起使用。通常最好不要使用mvn集成测试。请参阅以了解原因。仅为UTIL中的测试创建另一个测试,并将其绑定到要在其中运行测试的阶段
如果您使用的是JUnit,您也可以使用将测试分组。我找到了解决此问题的方法:
mvn测试-运行除“UTIL”之外的所有测试
mvn测试-P utilsTest-仅运行测试“utils”
实用测试
org.apache.maven.plugins
maven surefire插件
没有一个
**/乌提尔斯/**
测验
符合事实的
org.apache.maven.plugins
maven surefire插件
**/乌提尔斯/**
<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>
<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>