Spring Boot Testing & Testcontainers

    Question 1SPRING BOOT TESTING - @SpringBootTest Purpose

    What is the primary purpose of using `@SpringBootTest` in a test class?

    Question 2SPRING BOOT TESTING - Slicing Annotations

    Which of the following annotations provides slice testing for JPA repositories?

    Question 3SPRING BOOT TESTING - Mocking Dependencies

    What does the `@MockBean` annotation do in a Spring Boot test?

    Question 4SPRING BOOT TESTING - Code Snippet (MockMvc)

    What does the following test verify?

    @Autowired private MockMvc mockMvc; @Test void testHelloEndpoint() throws Exception { mockMvc.perform(get("/hello")) .andExpect(status().isOk()) .andExpect(content().string("Hello World")); }

    Question 5SPRING BOOT TESTING - Testcontainers Purpose

    What is the main advantage of using Testcontainers in Spring Boot tests?

    Question 6SPRING BOOT TESTING - Code Snippet (Postgres Testcontainer)

    What does the following snippet configure?

    @Testcontainers public class UserRepositoryTest { @Container static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine"); }

    Question 7SPRING BOOT TESTING - Dynamic Properties from Testcontainers

    Which method is typically used to register Testcontainers database properties with Spring Boot during tests?

    Question 8SPRING BOOT TESTING - Code Snippet (DynamicPropertySource)

    What is the purpose of this code?

    @DynamicPropertySource static void configure(DynamicPropertyRegistry registry) { registry.add("spring.datasource.url", postgres::getJdbcUrl); registry.add("spring.datasource.username", postgres::getUsername); registry.add("spring.datasource.password", postgres::getPassword); }

    Question 9SPRING BOOT TESTING - @TestConfiguration

    What is the purpose of `@TestConfiguration` in Spring Boot testing?

    Question 10SPRING BOOT TESTING - Code Snippet (Repository Test)

    What is this test checking?

    @DataJpaTest class UserRepositoryTest { @Autowired private UserRepository userRepository; @Test void testFindByEmail() { User user = new User(null, "Alice", "alice@mail.com"); userRepository.save(user); Optional<User> found = userRepository.findByEmail("alice@mail.com"); assertTrue(found.isPresent()); } }