测试模块中的文件夹结构

Folder structure in Test module

我是 Spring 的新手,也是测试人员。我对 Spring 测试模块的引导项目中的文件夹结构有疑问。

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

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

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

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

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

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".

Failsafe 插件(集成测试) :

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".