java - 如何指定要测试的不同类名模式?
问题描述
我又要回到 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
参考资料(堆栈溢出):
解决方案
您可以在 pom.xml 文件中尝试以下内容:
<build>
<testSourceDirectory>src/main/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
恕我直言,您应该只将测试放在测试包中,因为这是惯例。
推荐阅读
- python - 在 python pandas 过滤器中编辑数据并将其应用于原始数据框
- apache-spark - 如何使用 pyspark 从每日数据中计算 6 个月移动平均值
- dart - Catch 语句不会在异步函数的调试模式下捕获抛出的错误
- r - 如何使用 reticulate 包将任何 R 对象转换为 python 集合对象
- java - 在运行时,在 Java 中获取传递给方法的参数/参数的数量,无论是否带有可变参数
- xml - Orchestration with Error 中的 XPATH 问题具有无效的令牌
- sql - 根据与第一个表中的列名相关的另一个表中的值更新一个表中的 SQL Server 表值
- php - 如何在 Silverstripe 中限制对 $has_one 成员的对象访问?
- python - Python中的Unicode作为procmail过滤器的问题
- java - Maven 没有正确设置字符编码