Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Spring Boot 9 questions

Spring Boot Testing (JUnit, Mockito & Test Slices)

Test Spring boot applications. Master unit test mocks with Mockito, integration tests, and @WebMvcTest slices.

More Spring Boot
Interview questions 1–9 of 9
1

What is the difference between unit testing and integration testing in Spring Boot?

Unit testing verifies a single class or method in complete isolation, with all its dependencies replaced by mo...

Read answer →
2

What does @SpringBootTest do and when should you use it?

@SpringBootTest bootstraps the complete Spring application context for a test, the same way the real applicati...

Read answer →
3

What is the difference between @Mock, @MockBean, and @InjectMocks?

@Mock (Mockito) creates a mock object for use in plain unit tests that don't load any Spring context; it's pai...

Read answer →
4

How does @WebMvcTest work, and how is it different from @SpringBootTest?

@WebMvcTest loads only the Spring MVC layer — controllers, @ControllerAdvice, filters, and MVC-related configu...

Read answer →
5

What is @DataJpaTest and how does it test the repository layer?

@DataJpaTest loads only the JPA-related components — @Entity classes, Spring Data repositories, and the DataSo...

Read answer →
6

What is the difference between Mockito's when().thenReturn() and @Spy?

when(mock.method()).thenReturn(value) stubs a method on a full mock object, where every method returns a defau...

Read answer →
7

How do you use Testcontainers with Spring Boot for integration testing?

Testcontainers is a library that spins up real, disposable Docker containers (PostgreSQL, Kafka, Redis, etc.)...

Read answer →
8

How do you test exception handling and @ControllerAdvice with MockMvc?

Since @WebMvcTest loads the full MVC layer, including any @ControllerAdvice classes in the tested package, exc...

Read answer →
9

What are JUnit 5 lifecycle annotations (@BeforeEach, @BeforeAll, @AfterEach, @AfterAll)?

@BeforeEach runs before every individual test method, typically used to reset test data or re-create mocks so...

Read answer →