
java-testing
Test Java applications - JUnit 5, Mockito, integration testing, TDD patterns
- Installs
- 904
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-java --skill java-testing- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads java-testing automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Java Testing Skill
Write comprehensive tests for Java applications with modern testing practices.
Overview
This skill covers Java testing with JUnit 5, Mockito, AssertJ, and integration testing with Spring Boot Test and Testcontainers. Includes TDD patterns and test coverage strategies.
When to Use This Skill
Use when you need to:
- Write unit tests with JUnit 5
- Create mocks with Mockito
- Build integration tests with Testcontainers
- Implement TDD/BDD practices
- Improve test coverage
Topics Covered
JUnit 5
- @Test, @Nested, @DisplayName
- @ParameterizedTest with sources
- Lifecycle annotations
- Extensions and custom annotations
Mockito
- @Mock, @InjectMocks, @Spy
- Stubbing (when/thenReturn)
- Verification (verify, times)
- BDD style (given/willReturn)
AssertJ
- Fluent assertions
- Collection assertions
- Exception assertions
- Custom assertions
Integration Testing
- @SpringBootTest slices
- Testcontainers setup
- MockMvc for APIs
- Database testing
Quick Reference
// Unit Test with Mockito
@ExtendWith(MockitoExtension.class)
class UserServiceTest {
@Mock
private UserRepository userRepository;
@InjectMocks
private UserService userService;
@Test
@DisplayName("Should find user by ID")
void shouldFindUserById() {
// Given
User user = new User(1L, "John");
given(userRepository.findById(1L)).willReturn(Optional.of(user));
// When
Optional<User> result = userService.findById(1L);
// Then
assertThat(result)
.isPresent()
.hasValueSatisfying(u ->
assertThat(u.getName()).isEqualTo("John"));
then(userRepository).should().findById(1L);
}
}
// Parameterized Test
@ParameterizedTest
@CsvSource({
"valid@email.com, true",
"invalid-email, false",
"'', false"
})
void shouldValidateEmail(String email, boolean expected) {
assertThat(validator.isValid(email)).isEqualTo(expected);
}
// Integration Test with Testcontainers
@Testcontainers
@SpringBootTest
class OrderRepositoryIT {
@Container
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>("postgres:15");
@DynamicPropertySource
static void configure(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.datasource.username", postgres::getUsername);
registry.add("spring.datasource.password", postgres::getPassword);
}
@Autowired
private OrderRepository repository;
@Test
void shouldPersistOrder() {
Order saved = repository.save(new Order("item", 100.0));
assertThat(saved.getId()).isNotNull();
}
}
// API Test with MockMvc
@WebMvcTest(UserController.class)
class UserControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private UserService userService;
@Test
void shouldReturnUser() throws Exception {
given(userService.findById(1L))
.willReturn(Optional.of(new User(1L, "John")));
mockMvc.perform(get("/api/users/1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.name").value("John"));
}
}
Test Data Builders
public class UserTestBuilder {
private Long id = 1L;
private String name = "John Doe";
private String email = "john@example.com";
private boolean active = true;
public static UserTestBuilder aUser() {
return new UserTestBuilder();
}
public UserTestBuilder withName(String name) {
this.name = name;
return this;
}
public UserTestBuilder inactive() {
this.active = false;
return this;
}
public User build() {
return new User(id, name, email, active);
}
}
// Usage
User user = aUser().withName("Jane").inactive().build();
Coverage Goals
<!-- JaCoCo configuration -->
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
Troubleshooting
Common Issues
| Problem | Cause | Solution |
|---|---|---|
| Mock not working | Missing @ExtendWith | Add MockitoExtension |
| NPE in test | Mock not initialized | Check @InjectMocks |
| Flaky test | Shared state | Isolate test data |
| Context fails | Missing bean | Use @MockBean |
Debug Checklist
□ Run single test in isolation
□ Check mock setup matches invocation
□ Verify @BeforeEach setup
□ Review @Transactional boundaries
□ Check for shared mutable state
Usage
Skill("java-testing")
Related Skills
java-testing-advanced- Advanced patternsjava-spring-boot- Spring test slices
FAQ
What does the java-testing skill do?
Test Java applications - JUnit 5, Mockito, integration testing, TDD patterns
How do I install java-testing?
Run npx skills add https://github.com/pluginagentmarketplace/custom-plugin-java --skill java-testing in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/java-testing/ (personal) or .claude/skills/java-testing/ (project).
Which AI agents can use java-testing?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is java-testing safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains java-testing?
It is published by pluginagentmarketplace in pluginagentmarketplace/custom-plugin-java. It has 904 recorded installs.
More from pluginagentmarketplace/custom-plugin-java
java-spring-boot
pluginagentmarketplace/custom-plugin-java
Build production Spring Boot applications - REST APIs, Security, Data, Actuator
java-maven
pluginagentmarketplace/custom-plugin-java
Master Apache Maven - POM configuration, plugins, lifecycle, dependency management
java-fundamentals
pluginagentmarketplace/custom-plugin-java
Master core Java programming - syntax, OOP, collections, streams, and exception handling
java-jpa-hibernate
pluginagentmarketplace/custom-plugin-java
Master JPA/Hibernate - entity design, queries, transactions, performance optimization
java-microservices
pluginagentmarketplace/custom-plugin-java
Build microservices - Spring Cloud, service mesh, event-driven, resilience patterns
java-performance
pluginagentmarketplace/custom-plugin-java
JVM performance tuning - GC optimization, profiling, memory analysis, benchmarking
Popular testing & qa skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
grilling
mattpocock/skills
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
migrate-to-shoehorn
mattpocock/skills
Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.
run-train
lllllllama/rigorpilot-skills
Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.
test-driven-development
obra/superpowers
Use when implementing any feature or bugfix, before writing implementation code
finishing-a-development-branch
obra/superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work