What does this skill do?

The Spring Boot TDD Skill provides a complete workflow for implementing test-driven development in Spring Boot services. It covers unit testing with JUnit 5 and Mockito, web-layer testing with MockMvc, integration with SpringBootTest, and persistence testing with Testcontainers, ensuring over 80% coverage validated with JaCoCo.

Unit Tests
Write tests using JUnit 5 and Mockito, following the Arrange-Act-Assert pattern for services and business logic.
Driver Tests
Validate REST endpoints with MockMvc and @WebMvcTest without starting the entire server.
Integration Tests
Run end-to-end tests using @SpringBootTest and AutoConfigureMockMvc to validate the entire assembly.
Endurance Tests
Use @DataJpaTest with Testcontainers to test repositories against actual Postgres or Redis instances.

Usage examples

🧪 Service unit test
Create a unit test using Mockito for the `create` method of the `MarketService` to verify that it saves correctly.
🌐 REST Controller Test
Create a test using MockMvc for the GET /api/markets endpoint to verify that it returns a 200 status code and a JSON array.
🔗 Complete integration test
Write an integration test using SpringBootTest that sends a POST request to /api/markets and verifies that the resource is created.
📊 Check JaCoCo Coverage
Configure JaCoCo to fail the build if coverage is less than 80% and generate the HTML report.

Features

Complete TDD Cycle Step-by-Step Guide to the Red-Green-Refactor Workflow: Test First, Minimal Implementation, Refactoring with Passing Tests.
Four levels of testing It covers unit testing (service), web testing (controller), integration testing (end-to-end), and persistence testing (repository) with real-world examples.
Complete testing stack It integrates JUnit 5, Mockito, MockMvc, SpringBootTest, DataJpaTest, and Testcontainers into a coherent workflow.
Coverage Validation Configure JaCoCo to measure and enforce a minimum coverage of 80% in CI pipelines.
Patterns and builders It includes recommended patterns such as Arrange-Act-Assert, test data builders, and reusable containers.

Frequently asked questions

The skill is compatible with Spring Boot 2.7+ and 3.x. The examples use JUnit 5 and modern Spring Test annotations.
Yes. Testcontainers requires Docker to launch Postgres, Redis, or other database containers during testing.
Run `mvn verify` (Maven) or `./gradlew test jacocoTestReport` (Gradle). JaCoCo generates the report and may cause the build to fail if the configured threshold is not met.
Yes. The skill includes configuration for Maven, but the concepts and annotations are identical in Gradle. Only the syntax of the JaCoCo plugin changes.
TDD Spring Boot — Test-Driven Development with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.