spring-boot-testing

Selects and implements Spring Boot test slices, Testcontainers, Mockito, and AssertJ techniques.

Updated Sep 10, 2026
One-click install
npx skills add https://github.com/serpro-workshop-fortaleza/datacorp-sifap-modernization-team-kit --skill spring-boot-testing-serpro-workshop-fortaleza
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: spring-boot-testing
Source: https://github.com/serpro-workshop-fortaleza/datacorp-sifap-modernization-team-kit/tree/main/.github/skills/spring-boot-testing
Command: npx skills add https://github.com/serpro-workshop-fortaleza/datacorp-sifap-modernization-team-kit --skill spring-boot-testing-serpro-workshop-fortaleza

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Choosing the wrong Spring Boot testing technique leads to slow, brittle test suites. This Skill guides you to the narrowest test slice (@WebMvcTest, @DataJpaTest, @RestClientTest, @JsonTest, @SpringBootTest) that gives confidence, pinned to the Spring Boot 3.3 + JUnit 5 stack. ## Core Features & Use Cases - Test Slice Selection: Decision matrix and quick decision tree mapping each scenario (controller, repository, REST client, JSON mapping, full integration) to the right annotation. - Real Database Testing: Testcontainers configuration for running @DataJpaTest and @SpringBootTest against a real PostgreSQL 16 instead of H2. - Assertion & Tooling Guidance: AssertJ fluent assertions for scalars and collections, classic MockMvc patterns, Instancio test data generation, and context caching for faster suites. - Use Case: You need to test a JPA repository query. The Skill directs you to @DataJpaTest with a PostgreSQL Testcontainer, TestEntityManager for data setup, and AssertJ assertions, while keeping newer Spring Boot 3.4+/4.0 APIs (MockMvcTester, @MockitoBean, RestTestClient) clearly marked as out of scope. ## Quick Start Ask which Spring Boot test slice to use for your controller or repository and request a complete test class using Testcontainers and AssertJ.

Frequently Asked Questions about spring-boot-testing

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

FAQPage Schema
How do I choose between @WebMvcTest, @DataJpaTest, and @SpringBootTest?▼

Use @WebMvcTest for controller and HTTP semantics, @DataJpaTest for repository queries and JPA mappings, and @SpringBootTest only for full integration flows. The rule is to pick the narrowest slice that still gives confidence, keeping the suite fast.

How to test a Spring Data JPA repository against a real PostgreSQL database?▼

Annotate the test with @DataJpaTest, @Testcontainers, and @AutoConfigureTestDatabase(replace = NONE), then declare a static PostgreSQLContainer with @Container and @ServiceConnection. Use TestEntityManager to persist and flush test data before asserting query results.

Should I use MockMvc or MockMvcTester in Spring Boot 3.3?▼

In Spring Boot 3.3 use classic MockMvc with perform() and andExpect(), since MockMvcTester requires Spring Boot 3.4 or later. The same applies to @MockBean versus @MockitoBean, which only exists from 3.4 onward.

Does @DataJpaTest use H2 by default, and is that a problem?▼

Yes, @DataJpaTest uses an embedded H2 database by default, which can miss database-specific behavior. Replacing it with a Testcontainers PostgreSQL instance gives parity with production and supports features like JSONB columns.

Why is my Spring Boot test suite slow and how do I fix it?▼

Slowness usually comes from loading many distinct application contexts. Group tests by identical configuration, minimize @TestPropertySource variations, avoid @DirtiesContext, and prefer narrow slices so the Spring context cache is reused.

When should I use Instancio for test data generation?▼

Use Instancio when entities or DTOs have three or more properties, to avoid repetitive builder or setter calls. Set only the fields relevant to the test and let Instancio fill the rest with valid random data.