421-frameworks-quarkus-testing-unit-tests
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseQuarkus unit testing
Quarkus单元测试
Apply fast testing strategies for Quarkus: Mockito-first, QuarkusTest when CDI wiring matters.
What is covered in this Skill?
- Pure JUnit 5 + Mockito without container boot (@ExtendWith(MockitoExtension.class))
- @QuarkusTest with @InjectMock for full CDI bean replacement
- @InjectSpy for partial mocking — real bean wrapped as spy, specific methods overridden
- REST Assured for HTTP-level @QuarkusTest resource tests
- @ParameterizedTest with @CsvSource (inline data) and @MethodSource (complex objects)
- QuarkusTestProfile and @TestProfile for test-specific configuration overrides
- Naming conventions: *Test → Surefire (fast phase), *IT → Failsafe (verify phase)
- When to escalate to integration tests ()
@422
Scope: Apply recommendations based on the reference rules and good/bad code examples.
为Quarkus应用应用快速测试策略:优先使用Mockito,当CDI依赖注入至关重要时使用QuarkusTest。
本Skill涵盖哪些内容?
- 无需启动容器的纯JUnit 5 + Mockito测试(@ExtendWith(MockitoExtension.class))
- 使用@InjectMock进行完整CDI Bean替换的@QuarkusTest
- 使用@InjectSpy进行部分模拟——将真实Bean包装为spy,重写特定方法
- 用于HTTP层面@QuarkusTest资源测试的REST Assured
- 搭配@CsvSource(内联数据)和@MethodSource(复杂对象)的@ParameterizedTest
- 用于测试特定配置覆盖的QuarkusTestProfile和@TestProfile
- 命名约定:*Test → Surefire(快速阶段),*IT → Failsafe(验证阶段)
- 何时升级到集成测试()
@422
范围: 根据参考规则和代码示例(优/劣)应用建议。
Constraints
约束条件
Compile before test refactors; verify the full suite after.
- MANDATORY: Run or
./mvnw compilebefore applying any changemvn compile - PREREQUISITE: Project must compile before applying test improvements
- SAFETY: If compilation fails, stop immediately
- BLOCKING CONDITION: Compilation errors must be resolved by the user before proceeding
- VERIFY: Run or
./mvnw clean verifyafter applying improvementsmvn clean verify - BEFORE APPLYING: Read the reference for detailed rules and examples
在重构测试前先编译;之后验证整个测试套件。
- 强制要求:在进行任何更改前运行或
./mvnw compilemvn compile - 前提条件:项目必须能正常编译才能应用测试改进
- 安全要求:如果编译失败,立即停止操作
- 阻塞条件:用户必须先解决编译错误才能继续
- 验证:应用改进后运行或
./mvnw clean verifymvn clean verify - 应用前:阅读参考文档获取详细规则和示例
When to use this skill
何时使用本Skill
- Add or improve unit tests in a Quarkus project
- Reduce slow @QuarkusTest usage with Mockito-first tests
- Add @InjectSpy partial mocking or QuarkusTestProfile configuration in Quarkus tests
- Convert repeated test methods to @ParameterizedTest with @CsvSource or @MethodSource
- 在Quarkus项目中添加或改进单元测试
- 用优先使用Mockito的测试减少缓慢的@QuarkusTest使用
- 在Quarkus测试中添加@InjectSpy部分模拟或QuarkusTestProfile配置
- 将重复的测试方法转换为搭配@CsvSource或@MethodSource的@ParameterizedTest
Reference
参考资料
For detailed guidance, examples, and constraints, see references/421-frameworks-quarkus-testing-unit-tests.md.
如需详细指南、示例和约束条件,请查看references/421-frameworks-quarkus-testing-unit-tests.md。