Spring Boot Tutorial
Learn Spring Boot with the following in-depth tutorials, covering from basic to advanced concepts such as packaging and monitoring.
Learn Spring Boot with the following in-depth tutorials, covering from basic to advanced concepts such as packaging and monitoring.
Use @RestClientTest and MockRestServiceServer to verify an outgoing Spring Boot 4 RestClient request, JSON mapping, and 404 handling with runnable tests.
Test Spring Data JPA repositories with @DataJpaTest on Spring Boot 4.1.2. Run H2 query tests, verify rollback behavior, and see how to keep a configured datasource.
Use Spring Boot 4 @MockitoBean in MVC slice and full-context controller tests. Compare it with a plain Mockito mock and see when a missing bean is created or an existing one replaced.
Test a Spring WebFlux controller with @WebFluxTest, WebTestClient and @MockitoBean on Spring Boot 4.1.2. Verify JSON, 404 responses and the difference from a live-server test.
Test a Spring Boot 4.1.2 REST API with @SpringBootTest and H2. Compare real HTTP and MockMvc tests, seed data with @Sql, and mock only the notification boundary.
Test a Spring Boot REST controller with JUnit and Mockito. Compare direct method tests, standalone MockMvc and @WebMvcTest using verified GET, POST and 404 examples.
Use Spring Boot @TestConfiguration to add fixed test beans without losing production wiring. Compare nested and imported configurations in a runnable Boot 4.1.2 example.
Test asynchronous Spring MVC controllers with MockMvc and MockMvcTester. Run Spring Boot 4.1.2 examples for CompletableFuture, Callable, DeferredResult, and error responses.
Unit test a Spring Boot service with JUnit and Mockito. Mock the repository with @Mock, build the service with @InjectMocks, stub with when().thenReturn() and check calls with verify(). Also covers @MockitoBean in @SpringBootTest, thenThrow, ArgumentCaptor, BDDMockito, strict stubs and the Mockito Java agent on Java 21+.
Test Spring Boot REST controllers with MockMvc and @WebMvcTest. Replace the service with a @MockitoBean mock and send GET, POST, PUT and DELETE requests with JSON. Then check status codes, validation errors and @RestControllerAdvice responses. Also covers MockMvcTester (AssertJ) and real andDo(print()) output on Spring Boot 4.1.1.
Test a Spring Boot POST endpoint with TestRestTemplate on a random port. Verify 201, response body, Location, read-back GET and a 400 error response.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.