
junit
JUnit 5 testing framework with Mockito integration. Covers unit tests, mocking, and Spring Boot test integration. USE WHEN: user mentions "junit", "java test", "mockito", asks about "@Test", "@Mock", "@InjectMocks", "unit test java", "spring boot test" DO NOT USE FOR: Integration tests with containers - use testcontainers; REST API tests - use rest-assured; E2E tests - use Selenium; JavaScript/TypeScript - use vitest or jest
- Installs
- 52
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/claude-dev-suite/claude-dev-suite --skill junit- 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 junit 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.
JUnit 5 - Quick Reference
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:junitfor comprehensive documentation.
When NOT to Use This Skill
- Integration Tests with Containers - Use
testcontainersfor Docker-based tests - REST API Testing - Use
rest-assuredfor HTTP/REST testing - E2E Web Testing - Use Selenium or Playwright
- JavaScript/TypeScript - Use
vitestorjestfor JS/TS - Database Integration Tests - Combine with
spring-boot-integrationskill
Essential Patterns
Basic Test
@Test
void shouldAddNumbers() {
assertEquals(5, calculator.add(2, 3));
assertThrows(ArithmeticException.class, () -> calculator.divide(10, 0));
}
Mockito + Service Test
@ExtendWith(MockitoExtension.class)
class UserServiceTest {
@Mock
private UserRepository userRepository;
@InjectMocks
private UserServiceImpl userService;
@Test
void shouldCreateUser() {
when(userRepository.save(any())).thenReturn(user);
UserResponse result = userService.create(request);
assertNotNull(result);
verify(userRepository, times(1)).save(any());
}
}
Spring Boot Test
@SpringBootTest
@ActiveProfiles("test")
class UserServiceIntegrationTest {
@Autowired
private UserService userService;
@MockBean
private UserRepository userRepository;
@Test
void contextLoads() {
assertNotNull(userService);
}
}
Controller Test
@WebMvcTest(UserController.class)
class UserControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private UserService userService;
@Test
void shouldReturnUsers() throws Exception {
when(userService.findAll()).thenReturn(users);
mockMvc.perform(get("/api/v1/users"))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].name").value("John"));
}
}
Repository Test
@DataJpaTest
class UserRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private UserRepository userRepository;
@Test
void shouldFindByEmail() {
entityManager.persist(user);
Optional<User> found = userRepository.findByEmail("john@email.com");
assertTrue(found.isPresent());
}
}
Common Annotations
| Annotation | Usage |
|---|---|
@Test | Test method |
@BeforeEach | Setup before each test |
@Mock | Creates mock |
@InjectMocks | Injects mocks |
@SpringBootTest | Integration test |
@WebMvcTest | Controller test |
@DataJpaTest | Repository test |
Anti-Patterns
| Anti-Pattern | Why It's Bad | Solution |
|---|---|---|
| Using @SpringBootTest for unit tests | Extremely slow | Use @ExtendWith(MockitoExtension.class) |
| Testing private methods | Coupled to implementation | Test through public API |
| No mock cleanup | Tests affect each other | Use @BeforeEach, Mockito.reset() |
| Hardcoded test data | Hard to maintain | Use test data builders or factories |
| Not verifying mock interactions | Silent failures | Use verify() to ensure methods called |
| Too many assertions per test | Hard to debug | One logical assertion per test |
| Ignoring @Disabled tests | Technical debt accumulates | Fix or remove disabled tests |
Quick Troubleshooting
| Problem | Likely Cause | Solution |
|---|---|---|
| "NullPointerException in test" | Mock not injected | Check @Mock and @InjectMocks annotations |
| "Wanted but not invoked" | Method not called or wrong args | Verify method call, check argument matchers |
| Test takes too long | Using @SpringBootTest unnecessarily | Use Mockito for unit tests |
| "UnnecessaryStubbingException" | Mock setup but not used | Remove unused when() statements |
| Flaky test | Shared state or timing | Isolate setup, avoid Thread.sleep |
| "No tests found" | Wrong naming convention | Use test* prefix or @Test annotation |
Reference Documentation
FAQ
What does the junit skill do?
JUnit 5 testing framework with Mockito integration. Covers unit tests, mocking, and Spring Boot test integration. USE WHEN: user mentions "junit", "java test", "mockito", asks about "@Test", "@Mock", "@InjectMocks", "unit test java", "spring boot test" DO NOT USE FOR: Integration tests with containers - use testcontainers; REST API tests - use rest-assured; E2E tests - use Selenium; JavaScript/TypeScript - use vitest or jest
How do I install junit?
Run npx skills add https://github.com/claude-dev-suite/claude-dev-suite --skill junit 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/junit/ (personal) or .claude/skills/junit/ (project).
Which AI agents can use junit?
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 junit 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 junit?
It is published by claude-dev-suite in claude-dev-suite/claude-dev-suite. It has 52 recorded installs.
More from claude-dev-suite/claude-dev-suite
typescript-quality
claude-dev-suite/claude-dev-suite
TypeScript/JavaScript code quality with ESLint, Biome, and strict TypeScript. Covers linting, formatting, type safety, and best practices. USE WHEN: user works with "TypeScript", "JavaScript", "ESLint", "Biome", asks about "TS strict mode", "type safety", "linting rules", "code formatting" DO NOT USE FOR: SonarQube - use sonarqube skill, testing - use Vitest/Jest skills, security - use security skills
token-optimization
claude-dev-suite/claude-dev-suite
Token optimization best practices for MCP server and tool interactions. Minimizes token consumption while maintaining effectiveness. USE WHEN: user mentions "token usage", "optimize tokens", "reduce API calls", "MCP efficiency", asks about "how to use less tokens", "MCP best practices", "limit output size", "efficient queries" DO NOT USE FOR: Code optimization - use performance instead, Text compression - this is about API usage patterns, Cost optimization (infrastructure) - use cloud/DevOps skills
dotnet-security
claude-dev-suite/claude-dev-suite
Open the skill to read its SKILL.md instructions.
owasp-top-10
claude-dev-suite/claude-dev-suite
Open the skill to read its SKILL.md instructions.
webrtc
claude-dev-suite/claude-dev-suite
Open the skill to read its SKILL.md instructions.
email-sending
claude-dev-suite/claude-dev-suite
Open the skill to read its SKILL.md instructions.
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