如何指定要测试的不同类名模式?

我又要回到Java世界了...


我正在学习教程(https://spring.io/guides/gs/spring-boot/),当我使用 运行测试时mvn test,没有任何测试HelloControllerIT正在运行。似乎只考虑以“Test”结尾的类。我确信有一种方法可以添加其他模式,以便将HelloControllerIT其包含在内。


在哪里可以找到有关此主题的更多信息?


这看起来很简单,所以我可能没有在搜索中使用正确的关键字(例如,'java spring boot test pattern')。


更新


感谢 Yug Singh 的回答,我能够想出一个我感觉很好的解决方案。我将此添加到我的pom.xml文件中,现在我可以运行与集成测试分开的单元测试。


我忘记了简介...


+    <profiles>

+        <profile>

+            <id>integration</id>

+            <build>

+                <plugins>

+                    <plugin>

+                        <groupId>org.apache.maven.plugins</groupId>

+                        <artifactId>maven-surefire-plugin</artifactId>

+                        <configuration>

+                            <includes>

+                                <include>**/*IT.java</include>

+                            </includes>

+                        </configuration>

+                    </plugin>

+                </plugins>

+            </build>

+        </profile>

+    </profiles>

运行单元测试


mvn test

运行集成测试


mvn test -Pintegration


皈依舞
浏览 124回答 1
1回答

呼啦一阵风

您可以在 pom.xml 文件中尝试以下内容:<build>&nbsp; <testSourceDirectory>src/main/java</testSourceDirectory>&nbsp; <plugins>&nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp;<groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp;<artifactId>maven-surefire-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp;<version>2.16</version>&nbsp; &nbsp; &nbsp; &nbsp;<configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <includes>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<include>**/*.java</include>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </includes>&nbsp; &nbsp; &nbsp; &nbsp;</configuration>&nbsp; &nbsp; </plugin>&nbsp;</plugins>恕我直言,您应该将测试放在测试包中,因为这是惯例。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java