Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
claude-dev-suite avatar

Junit

  • 51 installs
  • 27 repo stars
  • Updated July 17, 2026
  • claude-dev-suite/claude-dev-suite

Write JUnit 5 unit tests with Mockito mocking and Spring Boot test integration using @Test, @Mock, and @InjectMocks.

About

Covers the JUnit 5 testing framework with Mockito integration for unit tests and mocking. A developer uses it when writing Java unit tests and Spring Boot test integrations.

  • JUnit 5 unit tests with @Test annotations
  • Mockito mocking with @Mock and @InjectMocks

Junit by the numbers

  • 51 all-time installs (skills.sh)
  • Ranked #1,222 of 2,153 Testing & QA skills by installs in the Skillselion catalog
  • Data as of Jul 29, 2026 (Skillselion catalog sync)
npx skills add https://github.com/claude-dev-suite/claude-dev-suite --skill junit

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs51
repo stars27
Last updatedJuly 17, 2026
Repositoryclaude-dev-suite/claude-dev-suite

What it does

Write JUnit 5 unit tests with Mockito mocking and Spring Boot test integration using @Test, @Mock, and @InjectMocks.

Files

SKILL.mdMarkdownGitHub ↗

JUnit 5 - Quick Reference

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: junit for comprehensive documentation.

When NOT to Use This Skill

  • Integration Tests with Containers - Use testcontainers for Docker-based tests
  • REST API Testing - Use rest-assured for HTTP/REST testing
  • E2E Web Testing - Use Selenium or Playwright
  • JavaScript/TypeScript - Use vitest or jest for JS/TS
  • Database Integration Tests - Combine with spring-boot-integration skill

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

AnnotationUsage
@TestTest method
@BeforeEachSetup before each test
@MockCreates mock
@InjectMocksInjects mocks
@SpringBootTestIntegration test
@WebMvcTestController test
@DataJpaTestRepository test

Anti-Patterns

Anti-PatternWhy It's BadSolution
Using @SpringBootTest for unit testsExtremely slowUse @ExtendWith(MockitoExtension.class)
Testing private methodsCoupled to implementationTest through public API
No mock cleanupTests affect each otherUse @BeforeEach, Mockito.reset()
Hardcoded test dataHard to maintainUse test data builders or factories
Not verifying mock interactionsSilent failuresUse verify() to ensure methods called
Too many assertions per testHard to debugOne logical assertion per test
Ignoring @Disabled testsTechnical debt accumulatesFix or remove disabled tests

Quick Troubleshooting

ProblemLikely CauseSolution
"NullPointerException in test"Mock not injectedCheck @Mock and @InjectMocks annotations
"Wanted but not invoked"Method not called or wrong argsVerify method call, check argument matchers
Test takes too longUsing @SpringBootTest unnecessarilyUse Mockito for unit tests
"UnnecessaryStubbingException"Mock setup but not usedRemove unused when() statements
Flaky testShared state or timingIsolate setup, avoid Thread.sleep
"No tests found"Wrong naming conventionUse test* prefix or @Test annotation

Reference Documentation

Related skills

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.