New to Claude Skills? Learn how to install them →

Saffaan-m on GitHub

Spring Boot TDD

Free

Guided TDD workflow for Spring Boot applications.

by affaan-m239.3k stars on affaan-m/ecc
1 views
Updated Aug 10, 2026
Get this skill

Free · Opens the source repo

What Spring Boot TDD does

The Spring Boot TDD skill provides a structured approach to test-driven development (TDD) for Spring Boot applications, emphasizing high code coverage and best practices. It guides developers through the TDD process using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo, ensuring that tests are written before code implementation. This skill is designed for developers looking to enhance their testing strategies and maintain robust code quality while adding features, fixing bugs, or refactoring existing code.

The workflow begins with writing failing tests, followed by implementing the minimum code necessary to pass those tests, and then refactoring the code while ensuring all tests remain green. This iterative process helps developers focus on functionality and design, leading to cleaner and more maintainable codebases. The skill also emphasizes the importance of achieving over 80% test coverage, which is crucial for identifying potential issues early in the development cycle.

In addition to unit tests, the skill covers integration testing with SpringBootTest and web layer testing using MockMvc, allowing developers to verify that their endpoints behave as expected. Testcontainers are utilized to create isolated testing environments that mimic production setups, ensuring that tests are reliable and repeatable. JaCoCo is included for measuring code coverage, helping teams identify untested parts of their code.

Overall, this skill is ideal for developers and teams working with Spring Boot who want to implement TDD effectively, improve code quality, and ensure that their applications are thoroughly tested before deployment.

When to use it

Use this skill when developing new features, fixing bugs, or refactoring existing code in Spring Boot applications.

When not to use it

This skill may not be suitable for projects that do not require rigorous testing or for teams unfamiliar with TDD practices.

What you can build with it

Adding a New Endpoint

When developing a new API endpoint, use this skill to write tests first, ensuring the functionality is implemented correctly from the start.

Fixing Bugs

Utilize the TDD approach to write tests that replicate the bug before fixing it, ensuring that the issue is resolved without introducing new problems.

Refactoring Existing Code

When refactoring, this skill helps maintain test coverage, allowing you to ensure that the refactored code still meets the original specifications.

How to install Spring Boot TDD

View source

1. Install with the skills CLI

npx skills add affaan-m/ecc/springboot-tdd --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by affaan-m

Flujo de Trabajo TDD en Spring Boot

Orientación TDD para servicios Spring Boot con 80%+ de cobertura (unit + integración).

Cuándo Usar

  • Nuevas funcionalidades o endpoints
  • Correcciones de bugs o refactorizaciones
  • Agregar lógica de acceso a datos o reglas de seguridad

Flujo de Trabajo

  1. Escribir pruebas primero (deben fallar)
  2. Implementar el código mínimo para que pasen
  3. Refactorizar con pruebas en verde
  4. Exigir cobertura con JaCoCo

Pruebas Unitarias (JUnit 5 + Mockito)

@ExtendWith(MockitoExtension.class)
class MarketServiceTest {
  @Mock MarketRepository repo;
  @InjectMocks MarketService service;

  @Test
  void createsMarket() {
    CreateMarketRequest req = new CreateMarketRequest("name", "desc", Instant.now(), List.of("cat"));
    when(repo.save(any())).thenAnswer(inv -> inv.getArgument(0));

    Market result = service.create(req);

    assertThat(result.name()).isEqualTo("name");
    verify(repo).save(any());
  }
}

Patrones:

  • Arrange-Act-Assert
  • Evitar mocks parciales; preferir stubbing explícito
  • Usar @ParameterizedTest para variantes

Pruebas de Capa Web (MockMvc)

@WebMvcTest(MarketController.class)
class MarketControllerTest {
  @Autowired MockMvc mockMvc;
  @MockBean MarketService marketService;

  @Test
  void returnsMarkets() throws Exception {
    when(marketService.list(any())).thenReturn(Page.empty());

    mockMvc.perform(get("/api/markets"))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.content").isArray());
  }
}

Pruebas de Integración (SpringBootTest)

@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
class MarketIntegrationTest {
  @Autowired MockMvc mockMvc;

  @Test
  void createsMarket() throws Exception {
    mockMvc.perform(post("/api/markets")
        .contentType(MediaType.APPLICATION_JSON)
        .content("""
          {"name":"Test","description":"Desc","endDate":"2030-01-01T00:00:00Z","categories":["general"]}
        """))
      .andExpect(status().isCreated());
  }
}

Pruebas de Persistencia (DataJpaTest)

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Import(TestContainersConfig.class)
class MarketRepositoryTest {
  @Autowired MarketRepository repo;

  @Test
  void savesAndFinds() {
    MarketEntity entity = new MarketEntity();
    entity.setName("Test");
    repo.save(entity);

    Optional<MarketEntity> found = repo.findByName("Test");
    assertThat(found).isPresent();
  }
}

Testcontainers

  • Usar contenedores reutilizables para Postgres/Redis que reflejen producción
  • Conectar mediante @DynamicPropertySource para inyectar URLs JDBC en el contexto de Spring

Cobertura (JaCoCo)

Fragmento Maven:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.14</version>
  <executions>
    <execution>
      <goals><goal>prepare-agent</goal></goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>verify</phase>
      <goals><goal>report</goal></goals>
    </execution>
  </executions>
</plugin>

Aserciones

  • Preferir AssertJ (assertThat) para legibilidad
  • Para respuestas JSON, usar jsonPath
  • Para excepciones: assertThatThrownBy(...)

Builders de Datos de Prueba

class MarketBuilder {
  private String name = "Test";
  MarketBuilder withName(String name) { this.name = name; return this; }
  Market build() { return new Market(null, name, MarketStatus.ACTIVE); }
}

Comandos de CI

  • Maven: mvn -T 4 test o mvn verify
  • Gradle: ./gradlew test jacocoTestReport

Recuerda: Mantener las pruebas rápidas, aisladas y deterministas. Probar comportamiento, no detalles de implementación.

Frequently asked questions about Spring Boot TDD

Similar skills