Spring Boot Test

Related Tags

Tutorials

Unit test spring boot async rest controller

Test Spring Boot Async REST Controller with MockMvc

To test an async Spring MVC controller with MockMvc, we perform the request, check asyncStarted() and call asyncDispatch() to get the final response. MockMvcTester does both steps in one exchange() call.

Spring Boot @DataJpaTest

Spring boot @DataJpaTest annotation focuses on JPA components and apply configuration only relevant to JPA tests. It helps in testing @Repository classes.

Spring Boot @MockBean Example

Spring boot @MockBean annotation used to add mocks to a Spring ApplicationContext. In this tutorial, we will learn the different ways to use this annotation.

Spring Boot Integration Test With @SpringBootTest and H2

Write Spring Boot integration tests that start the real app with @SpringBootTest, call the REST API over HTTP with RestTestClient and check an H2 database. Covers @Sql test data, @MockitoBean for external systems, MockMvc, TestRestTemplate in Spring Boot 4, Failsafe and context caching.

Spring Boot Mockito JUnit Example: Unit Test a Service

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+.

Spring Boot MockMvc Example with @WebMvcTest and MockitoBean

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.

Testing POST APIs using Spring Boot TestRestTemplate

Learn to consume HTTP POST REST API with Spring TestRestTemplate. In this post request test example, we will be sending request body along with request headers. 1. Maven dependencies Make sure, you have spring-boot-starter-test dependency in your project to get access to TestRestTemplate class in runtime. If you are using …

About Us

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.