首页/ 学科题库/ maven/ 测试资源与环境配置
maven 实战教程

测试资源与环境配置

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 测试配置
想在手机上练这篇的配套题目?
使用微信 卷王开发者小程序/App,首页顶部扫一扫识别下方二维码,即可解锁本讲对应真题与错题本。
了解产品 App
← 上一篇 集成测试配置与执行 下一篇 → 测试并行与性能优化