springboot-tdd

Guides test-driven development of Spring Boot services using JUnit 5, Mockito, MockMvc, and Testcontainers.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill springboot-tdd-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: springboot-tdd
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/springboot-tdd
Command: npx skills add https://github.com/Femad-6/my-skills --skill springboot-tdd-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Spring Boot tests requires choosing the right test slice, mocking strategy, and coverage tooling, and teams often skip tests or write brittle ones without a clear TDD workflow. ## Core Features & Use Cases - Layered Test Patterns: Provides ready-to-use templates for unit tests (JUnit 5 + Mockito), web layer tests (MockMvc), integration tests (@SpringBootTest), and persistence tests (@DataJpaTest with Testcontainers). - Coverage Enforcement: Includes JaCoCo Maven configuration and CI commands to maintain 80%+ coverage across unit and integration tests. - Use Case: When adding a new REST endpoint to a Spring Boot service, follow the red-green-refactor workflow: write a failing MockMvc test first, implement the controller, then add repository tests backed by a Testcontainers Postgres instance. ## Quick Start Ask the AI to write tests first for a new Spring Boot endpoint using JUnit 5, Mockito, and MockMvc following the TDD workflow.

Frequently Asked Questions about springboot-tdd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for a Spring Boot service with Mockito?

Use @ExtendWith(MockitoExtension.class) with @Mock for dependencies and @InjectMocks for the service under test. Stub calls with when(...).thenReturn(...) and verify interactions with verify(repo).save(any()), following the Arrange-Act-Assert pattern.

How to test a Spring Boot REST controller with MockMvc?

Annotate the test with @WebMvcTest(YourController.class), autowire MockMvc, and mock the service with @MockBean. Perform requests with mockMvc.perform(get("/api/...")) and assert responses using status().isOk() and jsonPath expressions.

Should I use @DataJpaTest or @SpringBootTest for repository testing?

Use @DataJpaTest for isolated JPA repository tests, paired with Testcontainers to run against a real database like Postgres. Reserve @SpringBootTest for full integration tests that load the entire application context.

Does Testcontainers work with Spring Boot integration tests?

Yes, Testcontainers runs reusable Docker containers for databases like Postgres or Redis during tests. Wire container settings into the Spring context using @DynamicPropertySource to inject JDBC URLs, and disable database replacement with @AutoConfigureTestDatabase.

How do I enforce code coverage in a Spring Boot Maven project?

Add the jacoco-maven-plugin with the prepare-agent goal and bind the report goal to the verify phase. Run mvn verify to execute tests and generate the coverage report, targeting 80%+ coverage across unit and integration tests.