testing-java
Skill9 starsChanged 8 months agoMITView on GitHub
Java testing with JUnit 5 and Mockito: test lifecycle, mocking, and integration test patterns
In this repository31 other files it gives its agents.
- git-workflow-releaseSkill
- skill-authoring-generalSkill
- git-workflow-releaseSkill
- skill-authoring-generalSkill
- accessibility-generalSkill
- accessibility-react-nativeSkill
- architecture-generalSkill
- architecture-pythonSkill
- assistant-rocky-lti-assistSkill
- assistant-ucd-mobileSkill
- ci-cd-github-actionsSkill
- code-review-generalSkill
- code-review-pythonSkill
- code-review-typescriptSkill
- data-science-pythonSkill
- design-frontendSkill
- documentation-projectSkill
- documentation-readmeSkill
- git-workflow-generalSkill
- git-workflow-monorepoSkill
- git-workflow-pr-generatorSkill
- git-workflow-releaseSkill
- infrastructure-terraformSkill
- package-management-pythonSkill
- project-management-jiraSkill
- refactoring-typescriptSkill
- security-generalSkill
- skill-authoring-generalSkill
- testing-generalSkill
- testing-pythonSkill
- testing-typescriptSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 45
Use @Mock and @InjectMocks with MockitoExtension — avoid Mockito.mock() in tests.
- Very specific: line 46
Verify critical interactions: verify(paymentGateway, times(1)).charge(expectedAmount).
- Very specific: line 47
Use @Captor to capture and assert arguments passed to mocks.
- Distinctive: line 51
Use an in-memory DB (H2) for repository tests.
- Very specific: line 56
Use JaCoCo: gradle jacocoTestReport and enforce with jacocoTestCoverageVerification.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Testing — Java
Framework
- JUnit 5 (
@Test,@BeforeEach,@AfterEach,@ParameterizedTest). - Mockito for mocking.
- Run:
mvn test/gradle test
Test Structure
@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()));
}
}Parameterized Tests
@ParameterizedTest
@ValueSource(strings = {"", " ", "\t"})
void shouldReturnTrueForBlankStrings(String value) {
assertTrue(StringUtils.isBlank(value));
}Mocking Rules
- Use
@Mockand@InjectMockswithMockitoExtension— avoidMockito.mock()in tests. - Verify critical interactions:
verify(paymentGateway, times(1)).charge(expectedAmount). - Use
@Captorto capture and assert arguments passed to mocks.
Integration Tests
- Annotate with
@SpringBootTestfor full context;@WebMvcTestfor controller slice only. - Use an in-memory DB (H2) for repository tests.
- Separate integration tests into
src/integrationTest/and run in a separate Gradle task.
Coverage
- Target 80%+ line coverage on service/domain layers.
- Use JaCoCo:
gradle jacocoTestReportand enforce withjacocoTestCoverageVerification.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

