spring-boot-testing

Configures Testcontainers integration tests and Mockito unit tests for Spring Boot projects.

Updated Apr 18, 2026
One-click install
npx skills add https://github.com/heiherilala-vawd/ompany-Management --skill spring-boot-testing-heiherilala-vawd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spring-boot-testing
Source: https://github.com/heiherilala-vawd/ompany-Management/tree/main/.agents/skills/spring-boot-testing
Command: npx skills add https://github.com/heiherilala-vawd/ompany-Management --skill spring-boot-testing-heiherilala-vawd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up a reliable test infrastructure for a Spring Boot application is repetitive and error-prone: wiring Testcontainers with a real PostgreSQL database, mocking JWT authentication, loading test data, and structuring integration versus unit tests all require boilerplate that teams often get wrong. ## Core Features & Use Cases - Integration Test Infrastructure: Provides ready-to-adapt templates for AbstractContextInitializer, TestUtils, and TestAuthSupport that spin up PostgreSQL via Testcontainers, run Flyway migrations plus test data SQL, and call endpoints through the generated API client with Bearer tokens. - Unit Test Patterns: Supplies Mockito-based service test templates (@ExtendWith(MockitoExtension.class), @Mock/@InjectMocks) and pure JUnit validator tests using AssertJ with Given/When/Then structure. - Test Data Management: Defines fixed-ID SQL test data scripts and an optional TestDataSqlLoader to reset database state between tests. - Use Case: When adding a new REST endpoint to a Spring Boot project, use this Skill to generate the matching *IT.java integration test with mocked JWT authentication and a real PostgreSQL container, plus the corresponding service unit test. ## Quick Start Set up the Spring Boot testing infrastructure with Testcontainers and write an integration test for the Company controller.

Frequently Asked Questions about spring-boot-testing

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

FAQPage Schema
How do I write Spring Boot integration tests with Testcontainers?

Create an AbstractContextInitializer that starts a PostgreSQLContainer in a static block and injects the JDBC URL, username, and password as Spring properties. Then annotate your test class with @SpringBootTest and @ContextConfiguration pointing to that initializer.

How to mock JWT authentication in Spring Boot tests?

Use @MockitoBean on the JwtUtils component and stub getUserEmailFromJwtToken to extract the email from the Bearer token, while validateJwtToken always returns true. This lets tests authenticate with simple 'Bearer email' tokens without real JWT signing.

Should I use H2 or Testcontainers for Spring Boot database tests?

Testcontainers with a real PostgreSQL container is recommended over H2 because it matches production behavior, supports PostgreSQL-specific SQL, and runs actual Flyway migrations. H2 can hide dialect differences that cause production failures.

What is the difference between @Mock and @MockitoBean in Spring tests?

@Mock with MockitoExtension creates plain mocks for unit tests without Spring context, while @MockitoBean replaces a bean inside the Spring application context for integration tests. Use @Mock for fast service tests and @MockitoBean only when the full context is loaded.

Why do Testcontainers tests fail to start?

Testcontainers requires a running Docker daemon; tests fail if Docker is not available or the socket path is misconfigured. Configure docker.client.strategy in testcontainers.properties and verify Docker is running before executing ./gradlew test.