java - 测试模块中的文件夹结构

标签 java spring unit-testing testing integration-testing

我也是 Spring 和 Testing 的新手。我对测试模块的 Spring Boot 项目中的文件夹结构有疑问。

以下项目结构是否适合测试模块中的集成和单元测试?或者最好的做法是什么?谢谢。

project/
├── main
└── test
    ├── integration
    │   └── SomeTestIT.java
    └── unit
        └── SomeTestU.java

最佳答案

Spring 和 Spring Boot 没有关于测试类布局的具体建议。

因此,您应该遵循构建工具的约定,可能是 Gradle 或 Maven。
对于他们来说,src/test/java 旨在包含要执行的测试类。 留着吧。

您可以在此目录中同时进行单元测试和集成测试,并使用后缀区分它们:Test 用于单元测试,IT 用于集成测试。
这些是 unit tests 的 Maven 约定和 integration tests .
通过坚持使用它们,您可以大大减少设置测试设施的工作量。

Surefire(单元测试):

Inclusions

By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:

"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".

"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".

"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".

"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".

故障安全插件(集成测试):

Inclusions

By default, the Failsafe Plugin will automatically include all test classes with the following wildcard patterns:

"**/IT*.java" - includes all of its subdirectories and all Java filenames that start with "IT".

"**/*IT.java" - includes all of its subdirectories and all Java filenames that end with "IT".

"**/*ITCase.java" - includes all of its subdirectories and all Java filenames that end with "ITCase".

关于java - 测试模块中的文件夹结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48865796/

相关文章:

java - session.save 不返回持久化对象,只返回标识符

java - 在 Visual Studio Code 中导入 .jar,类路径

php - 如何在 PHPUnit 中的测试之间共享夹具

c# - 如何在模拟中返回元组?

unit-testing - 单元测试期间调试断言的最佳实践

java - java中字符串的快速参数函数

java - NullPointerException - 位置 - getLatitude() 方法

java - 在 Spring Boot 中是否有自定义部署路径的标准方法?

java - 尝试在我的 Spring 项目中获取 InputStream 时出现 Http 502 错误

spring - 使用 Spring 记录 Jedis 客户端