322-frameworks-spring-boot-testing-integration-tests
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpring Boot Integration Testing
Spring Boot 集成测试
Apply Spring Boot integration testing guidelines for Spring Boot 4.0.x.
What is covered in this Skill?
- Integration test scope and purpose (verify wiring and contracts, not unit-test duplication)
- Testcontainers with @ServiceConnection for zero-config wiring (preferred)
- @DynamicPropertySource as fallback for containers without built-in service connection support
- Static @Container instances shared across test methods for performance
- MockMvcTester for fluent AssertJ-based HTTP assertions (Spring Boot 4.0.x)
- TestRestTemplate for full HTTP stack testing
- @DataJdbcTest / @DataJpaTest persistence slices (load only persistence layer, start faster)
- Data isolation: each test owns its scenario; no shared mutable state or ordering assumptions
- @MockitoBean for mock registration (Spring Boot 4.0.x — @MockBean removed)
- Resource lifecycle: Testcontainers JUnit integration for teardown; *IT / integration test separation
Scope: Apply recommendations based on the reference rules and good/bad code examples.
为Spring Boot 4.0.x应用集成测试指南。
本Skill涵盖哪些内容?
- 集成测试的范围与目的(验证组件连接与契约,而非重复单元测试)
- 使用带@ServiceConnection的Testcontainers实现零配置连接(推荐方案)
- 当容器不支持内置服务连接时,使用@DynamicPropertySource作为备选方案
- 静态@Container实例在测试方法间共享以提升性能
- 用于基于AssertJ的流畅HTTP断言的MockMvcTester(Spring Boot 4.0.x)
- 用于完整HTTP栈测试的TestRestTemplate
- @DataJdbcTest / @DataJpaTest持久化切片(仅加载持久化层,启动更快)
- 数据隔离:每个测试独立管理自身场景;无共享可变状态或执行顺序依赖
- @MockitoBean用于Mock注册(Spring Boot 4.0.x —— @MockBean已移除)
- 资源生命周期:Testcontainers与JUnit集成以实现资源清理;*IT / 集成测试分离
范围: 根据参考规则和代码示例(优/劣)应用建议。
Constraints
约束条件
Before applying any integration test changes, ensure the project compiles. If compilation fails, stop immediately. After applying improvements, run full verification.
- MANDATORY: Run or
./mvnw compilebefore applying any changemvn compile - SAFETY: If compilation fails, stop immediately
- VERIFY: Run or
./mvnw clean verifyafter applying improvementsmvn clean verify - BEFORE APPLYING: Read the reference for detailed rules and good/bad patterns
- EDGE CASE: If request scope is ambiguous, stop and ask a clarifying question before applying changes
- EDGE CASE: If required inputs, files, or tooling are missing, report what is missing and ask whether to proceed with setup guidance
在应用任何集成测试变更前,确保项目可编译。若编译失败,立即停止。应用改进后,执行完整验证。
- 强制要求:应用任何变更前运行或
./mvnw compilemvn compile - 安全规则:若编译失败,立即停止
- 验证步骤:应用改进后运行或
./mvnw clean verifymvn clean verify - 应用前准备:阅读参考文档以了解详细规则和优/劣模式
- 边缘情况:若请求范围不明确,停止操作并询问澄清问题后再进行变更
- 边缘情况:若缺少必要的输入、文件或工具,报告缺失内容并询问是否需要提供设置指导
When to use this skill
何时使用本Skill
- Review Java code for Spring Boot integration tests
- Apply best practices for Spring Boot integration tests in Java code
- Write @SpringBootTest integration tests with Testcontainers
- Configure dynamic properties for Spring integration tests
- Review Spring Boot integration test profiles
- 审查Spring Boot集成测试的Java代码
- 在Java代码中应用Spring Boot集成测试的最佳实践
- 使用Testcontainers编写@SpringBootTest集成测试
- 为Spring集成测试配置动态属性
- 审查Spring Boot集成测试配置文件
Workflow
工作流程
- Read reference and assess project context
Read and inspect the current project setup before proposing changes.
references/322-frameworks-spring-boot-testing-integration-tests.md- Gather scope and decide target improvements
Identify requested outcomes, constraints, and the minimum safe set of changes to apply.
- Apply framework-aligned changes
Implement or refactor configuration/code following the reference patterns and project conventions.
- Run verification and report results
Execute appropriate build/tests and summarize what changed, what was verified, and any follow-up actions.
- 阅读参考文档并评估项目上下文
阅读并检查当前项目设置,再提出变更建议。
references/322-frameworks-spring-boot-testing-integration-tests.md- 收集范围信息并确定目标改进方向
明确预期结果、约束条件,以及可应用的最小安全变更集。
- 应用符合框架要求的变更
遵循参考模式和项目约定实现或重构配置/代码。
- 执行验证并报告结果
运行相应的构建/测试,总结变更内容、验证情况及后续行动建议。
Reference
参考文档
For detailed guidance, examples, and constraints, see references/322-frameworks-spring-boot-testing-integration-tests.md.
如需详细指南、示例和约束条件,请查看references/322-frameworks-spring-boot-testing-integration-tests.md。