全部学科
Python全栈
python
NodeJS全栈
nodejs
📅 2026-05-23 8 分钟 ✍️ juanwangdev

测试资源与环境配置

测试资源目录存放测试专用配置文件。

测试资源目录

默认目录

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 测试配置
想在手机上练习这篇文章的配套题目?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码
← 上一篇 集成测试配置与执行
下一篇 → 测试并行与性能优化
扫码体验小程序
加载中
想在手机上刷题学习?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码