Spring Boot

Spring Boot Testing

Spring Boot testing: @SpringBootTest, @WebMvcTest, @DataJpaTest, MockMvc, TestRestTemplate, test slices

30 pertanyaan wawancara·
Mid-Level
1

Which annotation to use to load the full Spring Boot context for an integration test?

Jawaban

@SpringBootTest loads the full application context, including all beans and auto-configurations. This annotation is used for integration tests requiring the entire application. @WebMvcTest and @DataJpaTest only load part of the context (test slicing), while @ContextConfiguration is a lower-level annotation for manually configuring the context (more complex).

2

What is test slicing in Spring Boot?

Jawaban

Test slicing means loading only a specific part of the Spring context to speed up tests. For example, @WebMvcTest loads only web components (controllers, filters), while @DataJpaTest loads only JPA repositories. This reduces startup time and improves test performance by avoiding loading unnecessary beans.

3

Which annotation to use to test only a Spring MVC controller?

Jawaban

@WebMvcTest is specifically designed to test Spring MVC controllers. This annotation loads only web components (controllers, @ControllerAdvice, filters, interceptors) and automatically configures MockMvc. @SpringBootTest would load the entire context (unnecessary for testing a single controller), @DataJpaTest is for repositories, and @RestClientTest is for testing HTTP clients (RestTemplate, WebClient).

4

What is the purpose of @MockBean in Spring Boot Test?

5

Which object to use to simulate HTTP requests in a test with @WebMvcTest?

+27 pertanyaan wawancara

Kuasai Spring Boot untuk wawancara berikutnya

Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.

Mulai gratis