Saltar al contenido
Skillpedia
Pruebas40 mil · #7431

spring-boot-testing

Qué hace

Esta herramienta te ayuda a probar tu código de Spring Boot eligiendo los mejores métodos de prueba según lo que quieras comprobar. Usa herramientas modernas para que las pruebas sean más fáciles y claras.

Cuándo usarla

  • ✓Cuando quieres comprobar si un 'endpoint' (un punto de comunicación) de una web funciona correctamente.
  • ✓Cuando quieres comprobar si la parte de tu programa que guarda y lee datos es correcta.
  • ✓Cuando necesitas probar cómo se comunica tu programa con otros servicios por internet.

Link de la skill

https://github.com/github/awesome-copilot/blob/main/skills/spring-boot-testing/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/github/awesome-copilot/blob/main/skills/spring-boot-testing/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“¿Cómo pruebo si mi código que guarda datos en la base de datos funciona correctamente?”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La herramienta analiza lo que quieres probar y sugiere el mejor enfoque, como usar `@WebMvcTest` para probar la parte visual o `@DataJpaTest` para probar la parte de datos. También recomienda librerías como AssertJ para escribir pruebas más legibles.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

Spring Boot Testing

This skill provides expert guide for testing Spring Boot 4 applications with modern patterns and best practices.

Core Principles

  1. Test Pyramid: Unit (fast) > Slice (focused) > Integration (complete)
  2. Right Tool: Use the narrowest slice that gives you confidence
  3. AssertJ Style: Fluent, readable assertions over verbose matchers
  4. Modern APIs: Prefer MockMvcTester and RestTestClient over legacy alternatives

Which Test Slice?

Scenario Annotation Reference
Controller + HTTP semantics @WebMvcTest references/webmvctest.md
Repository + JPA queries @DataJpaTest references/datajpatest.md
REST client + external APIs @RestClientTest references/restclienttest.md
JSON (de)serialization @JsonTest references/test-slices-overview.md
Full application @SpringBootTest references/test-slices-overview.md

Test Slices Reference

Testing Tools Reference

Assertion Libraries

Testcontainers

Test Data Generation

Performance & Migration

Quick Decision Tree

Testing a controller endpoint?
  Yes → @WebMvcTest with MockMvcTester

Testing repository queries?
  Yes → @DataJpaTest with Testcontainers (real DB)

Testing business logic in service?
  Yes → Plain JUnit + Mockito (no Spring context)

Testing external API client?
  Yes → @RestClientTest with MockRestServiceServer

Testing JSON mapping?
  Yes → @JsonTest

Need full integration test?
  Yes → @SpringBootTest with minimal context config

Spring Boot 4 Highlights

  • RestTestClient: Modern alternative to TestRestTemplate
  • @MockitoBean: Replaces @MockBean (deprecated)
  • MockMvcTester: AssertJ-style assertions for web tests
  • Modular starters: Technology-specific test starters
  • Context pausing: Automatic pausing of cached contexts (Spring Framework 7)

Testing Best Practices

Code Complexity Assessment

When a method or class is too complex to test effectively:

  1. Analyze complexity - If you need more than 5-7 test cases to cover a single method, it's likely too complex
  2. Recommend refactoring - Suggest breaking the code into smaller, focused functions
  3. User decision - If the user agrees to refactor, help identify extraction points
  4. Proceed if needed - If the user decides to continue with the complex code, implement tests despite the difficulty

Example of refactoring recommendation:

// Before: Complex method hard to test
public Order processOrder(OrderRequest request) {
  // Validation, discount calculation, payment, inventory, notification...
  // 50+ lines of mixed concerns
}

// After: Refactored into testable units
public Order processOrder(OrderRequest request) {
  validateOrder(request);
  var order = createOrder(request);
  applyDiscount(order);
  processPayment(order);
  updateInventory(order);
  sendNotification(order);
  return order;
}

Avoid Code Redundancy

…

Preguntas frecuentes

¿Qué es la 'pirámide de pruebas'?

Es una forma de organizar las pruebas: muchas pruebas pequeñas y rápidas (unitarias), algunas de tamaño medio (slices) y unas pocas grandes y más lentas (de integración).

¿Por qué usar AssertJ?

AssertJ hace que las pruebas sean más fáciles de leer y de escribir, porque usa un lenguaje más natural para comprobar si los resultados son correctos.

¿Qué son los 'Test Slices'?

Son pruebas centradas en partes concretas de la aplicación, como solo la capa de red o solo la capa de datos, lo que las hace más rápidas y precisas.

Detalles

Descripción original del autor

Expert Spring Boot 4 testing specialist that selects the best Spring Boot testing techniques for your situation with Junit 6 and AssertJ.

repo: github/awesome-copilot

Popularidad

Estrellas en GitHub
40 mil
Posición en el ranking
#7431
Licencia
MIT
Actualizada
15/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas