测试资源与环境配置
测试资源目录存放测试专用配置文件。
测试资源目录
默认目录
XML
src/test/resources/
配置测试资源
Java
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering> <!-- 启用过滤 -->
</testResource>
</testResources>
</build>
测试配置文件
text
src/test/resources/
├── application-test.properties
├── test-data.sql
└── logback-test.xml
测试配置加载
Spring Boot 测试配置
text
@SpringBootTest
@ActiveProfiles("test")
class UserServiceTest {
// 使用 application-test.properties
}
要点总结
- src/test/resources 测试资源目录
- testResources 配置测试资源
- filtering=true 启用变量替换
- application-{profile}.properties 测试配置
📝 发现内容有误?点击此处直接编辑