junit-mockito-patterns
Installation
SKILL.md
JUnit5 + Mockito 测试规则
来源:https://junit.org/junit5/docs/current/user-guide/
Mockito:https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html
Capability Boundaries
✅ Strong Suits
- JUnit5 迁移规则 — @ExtendWith 替代 @RunWith, @Test 导入 org.junit.jupiter.api
- Mockito 规则 — @Mock(外部依赖) + @InjectMocks(被测试对象), 不 Mock POJO
- 测试隔离(FIRST原则) — Fast/Independent/Repeatable/Self-Validating/Timely
- 切片测试 — @WebMvcTest(Controller) / @DataJpaTest(Repository) / @JsonTest
- BDD风格 — BDDMockito.given()/willReturn()/then().should() 替代 when/thenReturn/verify
- 行为验证 — verify() + ArgumentCaptor
- @ParameterizedTest + @MethodSource — 参数化测试简化多场景
- @Nested 分组 — 组织相关测试场景