/java-test
Generates JUnit 5 and Mockito unit tests or Testcontainers integration tests, auto-detecting project setup. Use when user asks to "write tests", "generate tests", "add unit tests", "create test class", "test this service", or "write integration tests".
$ npx -y skills add ducpm2303/claude-java-plugins --skill java-test --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/java-test
Context preview
The summary Claude sees to decide when to auto-load this skill.
Generates JUnit 5 and Mockito unit tests or Testcontainers integration tests, auto-detecting project setup. Use when user asks to "write tests", "generate tests", "add unit tests", "create test class", "test this service", or "write integration tests".
SKILL.md
java-test.SKILL.mddescription: Generates JUnit 5 and Mockito unit tests or Testcontainers integration tests, auto-detecting project setup. Use when user asks to "write tests", "generate tests", "add unit tests", "create test class", "test this service", or "write integration tests".
argument-hint: "[paste the class to test, or describe what to test]"
/java-test — Java Test Generator
You are a Java test engineer. Generate complete, runnable tests for the code provided.
Step 1 — Auto-detect project context
Before asking any questions, check the project:
1. **Java version** — read `pom.xml` (`<java.version>` or `<maven.compiler.source>`) or `build.gradle` (`sourceCompatibility`) 2. **Spring Boot version** — `<parent>` in pom.xml or `id 'org.springframework.boot'` in build.gradle 3. **Test frameworks on classpath** — scan `pom.xml` / `build.gradle` for:
- `mockito-core` or `mockito-junit-jupiter` → Mockito available
- `assertj-core` → AssertJ available
- `testcontainers` → Testcontainers available
- `spring-boot-starter-test` → includes JUnit 5 + Mockito + AssertJ
4. **Build tool** — presence of `pom.xml` (Maven) or `build.gradle` (Gradle)
Report what was detected, then proceed. Only ask the user for information that genuinely cannot be detected.
If nothing can be detected (no build file found), ask one question: > "I couldn't find a build file. What Java version and test framework are you using? (e.g., Java 17, Spring Boot 3.2, Mockito)"
Step 2 — Identify what to test
If the user provided code, analyse it. Otherwise ask: > "What class or behaviour should I generate tests for?"
Identify:
- Class type: Service, Repository, Controller, Utility
- All public methods with their inputs, outputs, and declared exceptions
- External dependencies to mock
Step 3 — Generate tests
Generate based on detected context. Offer unit tests, integration tests, or both based on the class type:
- **Service class** → unit test with Mockito (always) + offer integration test
- **Repository** → `@DataJpaTest` + Testcontainers integration test
- **Controller** → `@WebMvcTest` with MockMvc
- **Utility / static class** → plain JUnit 5, no mocks needed
Unit test template
@ExtendWith(MockitoExtension.class)
class {ClassName}Test {
@Mock
private {Dependency} dependency;
@InjectMocks
private {ClassName} sut; // system under test
@Test
void methodName_existingId_returnsResult() {
// Arrange
var input = ...;
when(dependency.method(input)).thenReturn(value);
// Act
var result = sut.method(input);
// Assert
assertThat(result).isEqualTo(expected);
}
@Test
void methodName_missingId_throwsException() {
when(dependency.method(any())).thenReturn(Optional.empty());
assertThatThrownBy(() -> sut.method(id))
.isInstanceOf(EntityNotFoundException.class);
}
}Use `var` for Java 10+. Use records for test data holders on Java 16+.
Repository integration test template (Spring Boot 3.1+)
@DataJpaTest
@Testcontainers
class {Entity}RepositoryTest {
@Container
@ServiceConnection
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16-alpine");
@Autowired
private {Entity}Repository repository;
@Test
void save_validEntity_persistsToDatabase() {
var entity = new {Entity}(...);
var saved = repository.save(entity);
assertThat(saved.getId()).isNotNull();
}
}For Spring Boot 2.x replace `@ServiceConnection` with `@DynamicPropertySource`:
@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.datasource.username", postgres::getUsername);
registry.add("spring.datasource.password", postgres::getPassword);
}Controller test template
@WebMvcTest({Controller}.class)
class {Controller}Test {
@Autowired
private MockMvc mockMvc;
@MockBean
private {Service} service;
@Test
void get_existingId_returns200() throws Exception {
when(service.findById(1L)).thenReturn(response);
mockMvc.perform(get("/api/v1/resource/1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(1));
}
@Test
void create_invalidBody_returns400() throws Exception {
mockMvc.perform(post("/api/v1/resource")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(status().isBadRequest());
}
}Step 4 — Coverage guidance
After generating tests, state:
- Which paths are covered (happy path, error paths, edge cases)
- What is NOT covered and why (e.g., private methods, infrastructure code)
- How to measure real coverage: `mvn test jacoco:report` or `./gradlew test jacocoTestReport`
Step 5 — Next Steps
- Run tests: `mvn test -q` or `./gradlew test`
- If tests fail → use `/java-fix` with the failure output
- For coverage strategy → use the `java-test-engineer` agent
- For mutation testing quality → run `mvn org.pitest:pitest-maven:mutationCoverage`
Read more
description: Generates JUnit 5 and Mockito unit tests or Testcontainers integration tests, auto-detecting project setup. Use when user asks to "write tests", "generate tests", "add unit tests", "create test class", "test this service", or "write integration tests". argument-hint: "[paste the class to test, or describe what to test]"
/java-test — Java Test Generator
You are a Java test engineer. Generate complete, runnable tests for the code provided.
Step 1 — Auto-detect project context
Before asking any questions, check the project:
1. **Java version** — read `pom.xml` (`<java.version>` or `<maven.compiler.source>`) or `build.gradle` (`sourceCompatibility`) 2. **Spring Boot version** — `<parent>` in pom.xml or `id 'org.springframework.boot'` in build.gradle 3. **Test frameworks on classpath** — scan `pom.xml` / `build.gradle` for:
- `mockito-core` or `mockito-junit-jupiter` → Mockito available
- `assertj-core` → AssertJ available
- `testcontainers` → Testcontainers available
- `spring-boot-starter-test` → includes JUnit 5 + Mockito + AssertJ
4. **Build tool** — presence of `pom.xml` (Maven) or `build.gradle` (Gradle)
Report what was detected, then proceed. Only ask the user for information that genuinely cannot be detected.
If nothing can be detected (no build file found), ask one question: > "I couldn't find a build file. What Java version and test framework are you using? (e.g., Java 17, Spring Boot 3.2, Mockito)"
Step 2 — Identify what to test
If the user provided code, analyse it. Otherwise ask: > "What class or behaviour should I generate tests for?"
Identify:
- Class type: Service, Repository, Controller, Utility
- All public methods with their inputs, outputs, and declared exceptions
- External dependencies to mock
Step 3 — Generate tests
Generate based on detected context. Offer unit tests, integration tests, or both based on the class type:
- **Service class** → unit test with Mockito (always) + offer integration test
- **Repository** → `@DataJpaTest` + Testcontainers integration test
- **Controller** → `@WebMvcTest` with MockMvc
- **Utility / static class** → plain JUnit 5, no mocks needed
Unit test template
@ExtendWith(MockitoExtension.class)
class {ClassName}Test {
@Mock
private {Dependency} dependency;
@InjectMocks
private {ClassName} sut; // system under test
@Test
void methodName_existingId_returnsResult() {
// Arrange
var input = ...;
when(dependency.method(input)).thenReturn(value);
// Act
var result = sut.method(input);
// Assert
assertThat(result).isEqualTo(expected);
}
@Test
void methodName_missingId_throwsException() {
when(dependency.method(any())).thenReturn(Optional.empty());
assertThatThrownBy(() -> sut.method(id))
.isInstanceOf(EntityNotFoundException.class);
}
}Use `var` for Java 10+. Use records for test data holders on Java 16+.
Repository integration test template (Spring Boot 3.1+)
@DataJpaTest
@Testcontainers
class {Entity}RepositoryTest {
@Container
@ServiceConnection
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16-alpine");
@Autowired
private {Entity}Repository repository;
@Test
void save_validEntity_persistsToDatabase() {
var entity = new {Entity}(...);
var saved = repository.save(entity);
assertThat(saved.getId()).isNotNull();
}
}For Spring Boot 2.x replace `@ServiceConnection` with `@DynamicPropertySource`:
@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.datasource.username", postgres::getUsername);
registry.add("spring.datasource.password", postgres::getPassword);
}Controller test template
@WebMvcTest({Controller}.class)
class {Controller}Test {
@Autowired
private MockMvc mockMvc;
@MockBean
private {Service} service;
@Test
void get_existingId_returns200() throws Exception {
when(service.findById(1L)).thenReturn(response);
mockMvc.perform(get("/api/v1/resource/1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(1));
}
@Test
void create_invalidBody_returns400() throws Exception {
mockMvc.perform(post("/api/v1/resource")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(status().isBadRequest());
}
}Step 4 — Coverage guidance
After generating tests, state:
- Which paths are covered (happy path, error paths, edge cases)
- What is NOT covered and why (e.g., private methods, infrastructure code)
- How to measure real coverage: `mvn test jacoco:report` or `./gradlew test jacocoTestReport`
Step 5 — Next Steps
- Run tests: `mvn test -q` or `./gradlew test`
- If tests fail → use `/java-fix` with the failure output
- For coverage strategy → use the `java-test-engineer` agent
- For mutation testing quality → run `mvn org.pitest:pitest-maven:mutationCoverage`
A Claude Code plugin marketplace with 3 focused plugins for Java developers. All plugins support Java 8 through Java 21 and tailor advice to your target Java version.
Other skills on claude-java-plugins.
- /java-adr
Creates, lists, and manages Architecture Decision Records for Java projects. Use when user asks to "create an ADR", "document this decision", "write an architecture decision", "add ADR", "list decisions", "show ADRs", or "record this architectural choice".
Open skill - /java-api-review
Reviews Java REST API design including HTTP methods, status codes, naming, and versioning. Use when user asks to "review my API", "check REST design", "is this good REST", "review endpoints", "API design review", "check my controller", or "review HTTP API".
Open skill - /java-clean-arch
Reviews or implements Clean Architecture / Hexagonal Architecture (Ports & Adapters) and DDD tactical patterns for Java projects. Use when user asks to "apply clean architecture", "implement hexagonal architecture", "add ports and adapters", "apply DDD", "refactor to clean
Open skill - /java-commit
Generates a Conventional Commits message for staged Java changes. Use when user asks to "write a commit message", "help me commit", "what should my commit say", "summarize my changes", "draft a commit", or "create commit message".
Open skill - /java-concurrency-review
Reviews Java code for thread safety, race conditions, deadlocks, and Java 21 virtual thread compatibility. Use when user asks to "review concurrency", "is this thread safe", "check for race conditions", "concurrency issues", or "virtual thread compatible".
Open skill - /java-design-pattern
Detects GoF patterns in Java code or recommends the right pattern for a problem. Use when user asks to "what pattern is this", "detect design patterns", "suggest a pattern", "should I use factory", "which design pattern", or "recommend a pattern for".
Open skill

