521-frameworks-micronaut-testing-unit-tests
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMicronaut Unit Testing
Micronaut 单元测试
Apply fast testing strategies for Micronaut: Mockito-first, narrow @MicronautTest when HTTP or DI replacement is required.
What is covered in this Skill?
- Pure JUnit 5 + Mockito without container boot
- @MicronautTest with @MockBean factory methods for collaborators
- HttpClient blocking exchanges against the embedded server
- @Property for deterministic configuration in tests
- @ParameterizedTest with @CsvSource / @MethodSource
- Naming: *Test → Surefire; *IT → Failsafe when configured
- When to escalate to
@522
Scope: Apply recommendations based on the reference rules and good/bad code examples.
为 Micronaut 应用采用快速测试策略:优先使用 Mockito;仅在需要 HTTP 或 DI 替换时使用范围受控的 。
@MicronautTest此 Skill 涵盖哪些内容?
- 无需启动容器的纯 JUnit 5 + Mockito
- 使用 工厂方法为协作者提供 mock 的
@MockBean@MicronautTest - 使用 HttpClient 对嵌入式服务器执行阻塞式请求交互
- 使用 在测试中设置确定性配置
@Property - 配合
@ParameterizedTest/@CsvSource@MethodSource - 命名规则:→ Surefire;完成配置后,
*Test→ Failsafe*IT - 何时升级到
@522
范围: 根据参考规则以及良好/不良代码示例应用建议。
Constraints
约束
Compile before test refactors; verify the full suite after.
- 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 examples
- 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
- Add or improve unit tests in a Micronaut project
- Reduce unnecessary @MicronautTest usage with Mockito-first tests
- Write Mockito-first unit tests for Micronaut services
- Mock Micronaut bean collaborators in unit tests
- Review fast Micronaut tests without application context
- 为 Micronaut 项目添加或改进单元测试
- 减少不必要的 使用,改用 Mockito 优先的测试
@MicronautTest - 为 Micronaut 服务编写 Mockito 优先的单元测试
- 在单元测试中模拟 Micronaut bean 协作者
- 审查无需应用程序上下文的快速 Micronaut 测试
Workflow
工作流
- Read reference and assess project context
Read and inspect the current project setup before proposing changes.
references/521-frameworks-micronaut-testing-unit-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/521-frameworks-micronaut-testing-unit-tests.md- 收集范围并确定目标改进项
确定请求的预期结果、约束条件,以及需要应用的安全最小变更集。
- 应用与框架一致的变更
按照参考模式及项目约定实施或重构配置/代码。
- 运行验证并报告结果
执行适当的构建/测试,并总结变更内容、验证结果和后续操作。
Reference
参考资料
For detailed guidance, examples, and constraints, see references/521-frameworks-micronaut-testing-unit-tests.md.
有关详细指导、示例和约束,请参阅 references/521-frameworks-micronaut-testing-unit-tests.md。