Java testing with JUnit 5 and Mockito: test lifecycle, mocking, and integration test patterns
75
63%
Does it follow best practices?
Impact
92%
1.14xAverage score across 3 eval scenarios
Passed
No known issues
Optimize this skill with Tessl
npx tessl skill review --optimize ./skills/testing-java/SKILL.md@Test, @BeforeEach, @AfterEach, @ParameterizedTest).mvn test / gradle test@ExtendWith(MockitoExtension.class)
class OrderServiceTest {
@Mock
private PaymentGateway paymentGateway;
@InjectMocks
private OrderService orderService;
@Test
void shouldThrowOrderExceptionWhenPaymentFails() {
// Arrange
when(paymentGateway.charge(any())).thenThrow(new PaymentException("Declined"));
// Act & Assert
assertThrows(OrderException.class, () -> orderService.placeOrder(testOrder()));
}
}@ParameterizedTest
@ValueSource(strings = {"", " ", "\t"})
void shouldReturnTrueForBlankStrings(String value) {
assertTrue(StringUtils.isBlank(value));
}@Mock and @InjectMocks with MockitoExtension — avoid Mockito.mock() in tests.verify(paymentGateway, times(1)).charge(expectedAmount).@Captor to capture and assert arguments passed to mocks.@SpringBootTest for full context; @WebMvcTest for controller slice only.src/integrationTest/ and run in a separate Gradle task.gradle jacocoTestReport and enforce with jacocoTestCoverageVerification.c0b2e4b
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.