springboot-tdd

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill springboot-tdd-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: springboot-tdd
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/springboot-tdd
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill springboot-tdd-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Spring Boot tests is hard: developers struggle to choose the right test slice, mock dependencies correctly, mirror production databases in tests, and enforce meaningful coverage targets. This Skill provides a structured TDD workflow with ready-to-use patterns for every test layer. ## Core Features & Use Cases - Layered Test Patterns: Provides concrete examples for unit tests (JUnit 5 + Mockito), web layer tests (MockMvc), persistence tests (@DataJpaTest), and full integration tests (@SpringBootTest). - Production-Like Testing: Shows how to use Testcontainers with @DynamicPropertySource to run tests against real Postgres/Redis instances. - Coverage Enforcement: Includes JaCoCo Maven/Gradle configuration to maintain 80%+ coverage across unit and integration tests. - Use Case: When adding a new REST endpoint to a Spring Boot service, follow the workflow to write a failing MockMvc test first, implement the minimal controller code, then add repository tests with Testcontainers and verify coverage with mvn verify. ## Quick Start Ask the AI to apply the springboot-tdd workflow to write tests first for a new Spring Boot feature or bug fix, including unit, web, and integration test layers with JaCoCo coverage checks.

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 Spring Boot services with Mockito?▼

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

How to test Spring Boot REST controllers with MockMvc?▼

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

Should I use @DataJpaTest or @SpringBootTest for repository tests?▼

Use @DataJpaTest for isolated JPA repository tests, paired with Testcontainers via @AutoConfigureTestDatabase(replace = NONE) to run against a real database. Reserve @SpringBootTest for full integration tests covering the entire application context.

Does Testcontainers work with Spring Boot integration tests?▼

Yes, Testcontainers integrates with Spring Boot by defining reusable Postgres or Redis containers and injecting connection details via @DynamicPropertySource. This mirrors production infrastructure while keeping tests isolated and deterministic.

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

Configure 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 coverage reports, targeting 80%+ combined unit and integration coverage.

Why should I avoid partial mocks in Spring Boot tests?▼

Partial mocks blur the line between real and stubbed behavior, making tests fragile and hard to reason about. Prefer explicit stubbing of collaborators and test behavior rather than implementation details to keep tests fast and deterministic.