What is the role of the @WebMvcTest annotation in Spring testing?
@WebMvcTest tests Spring MVC controllers in isolation with MockMvc and mocked services. See working examples for JSON, validation, security and common errors.
2,882 posts about Java: questions with answers, tutorials and articles, newest first.
@WebMvcTest tests Spring MVC controllers in isolation with MockMvc and mocked services. See working examples for JSON, validation, security and common errors.
Test Spring Data JPA repositories with @DataJpaTest and Testcontainers, verify derived and JPQL queries, and know when to mock the repository instead.
@DataJpaTest is a Spring Boot test slice that loads only JPA repositories and a database, rolls back each test, and makes repository tests fast and isolated.
Assert the status code, headers and JSON body of REST endpoints in Spring Boot with MockMvc, TestRestTemplate and WebTestClient.
TestRestTemplate calls your Spring Boot endpoints in integration tests, returns error statuses without throwing and supports basic auth.
Integration test your own Spring Boot REST endpoints with WebTestClient and replace external REST dependencies with WireMock or MockRestServiceServer.
Mockito lets Java unit tests replace dependencies with controllable mocks and verify interactions. See JUnit 5 setup, matchers, spies and pitfalls.
A mock is a fully fake object; a spy wraps a real one. See how to use @Mock, @Spy, @MockitoBean and @MockitoSpyBean in Spring Boot tests.
@ActiveProfiles sets which Spring profiles are active in a test, so you can swap beans and load application-test properties without touching production config.
Write Spring Boot test configurations with @TestConfiguration, @MockitoBean, @ActiveProfiles and @DynamicPropertySource, and keep the context cache effective.
@BeforeEach and @AfterEach run setup and cleanup around every JUnit 5 test. Learn the lifecycle, JUnit 4 equivalents, and good usage patterns.
The JUnit 5 Assertions class verifies test results with static methods. Learn assertEquals, assertThrows, assertAll and timeouts, with working examples.
@Test marks a method that JUnit discovers and runs as a test. See JUnit 5 versus JUnit 4 differences, exception and timeout checks and lifecycle callbacks.
Load the real context with @SpringBootTest, use MockMvc or a random port, run a real database with Testcontainers and keep the suite fast with slices.
A context mock swaps a real Spring bean for a Mockito mock in tests. Learn where it fits, how to migrate to @MockitoBean and keep suites fast.
Let listener exceptions reach DefaultErrorHandler, retry with back-off and publish failures to a dead-letter topic. Includes deserialization errors and retry topics.
Test Spring services with plain Mockito, controllers with @WebMvcTest and MockMvc, and repositories with @DataJpaTest, using current Spring Boot 3.x annotations.
KStream is Kafka Streams' abstraction for an unbounded event stream. See how to configure and build a topology in Spring Boot and how it differs from KTable.
Write fast Spring Boot tests with JUnit 5 by combining Mockito unit tests, slice tests like @WebMvcTest and @DataJpaTest, and a few full @SpringBootTest integration tests.
JobLauncher starts a Spring Batch Job with JobParameters and returns a JobExecution. Learn async launching, restart rules and the exceptions it throws.