521-frameworks-micronaut-testing-unit-tests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Micronaut 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或依赖注入替换时再使用范围更窄的@MicronautTest。
本Skill涵盖哪些内容?
  • 无需启动容器的纯JUnit 5 + Mockito测试方案
  • 结合@MockBean工厂方法来模拟协作对象的@MicronautTest
  • 针对嵌入式服务器的HttpClient阻塞式交互
  • 用于测试中确定性配置的@Property
  • 搭配@CsvSource / @MethodSource的@ParameterizedTest
  • 命名规范:配置完成后,*Test由Surefire执行;*IT由Failsafe执行
  • 何时升级使用
    @522
适用范围: 根据参考规则和代码示例的优劣来应用相关建议。

Constraints

约束条件

Compile before test refactors; verify the full suite after.
  • MANDATORY: Run
    ./mvnw compile
    or
    mvn compile
    before applying any change
  • SAFETY: If compilation fails, stop immediately
  • VERIFY: Run
    ./mvnw clean verify
    or
    mvn clean verify
    after applying improvements
  • BEFORE APPLYING: Read the reference for detailed rules and examples
在重构测试前先编译;完成后验证整个测试套件。
  • 强制要求:在进行任何修改前,运行
    ./mvnw compile
    mvn compile
  • 安全提示:如果编译失败,请立即停止操作
  • 验证步骤:在完成优化后,运行
    ./mvnw clean verify
    mvn 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
  • 在Micronaut项目中添加或优化单元测试
  • 优先使用Mockito测试,减少不必要的@MicronautTest使用

Reference

参考资料

For detailed guidance, examples, and constraints, see references/521-frameworks-micronaut-testing-unit-tests.md.
如需详细指南、示例和约束条件,请查看references/521-frameworks-micronaut-testing-unit-tests.md