我也是 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/