Advanced Spring Boot Testing with JUnit & Mockito: Mastery Quiz
Test your expertise in advanced testing techniques using Spring Boot, JUnit, and Mockito.
Questions in this quiz
10 questions on Advanced Spring Boot Testing with JUnit & Mockito: Mastery Quiz. Work through them here, then start the quiz to answer them and see your score.
1.In Spring Boot, what is the primary purpose of using @MockBean in a test class?
- ATo create a spy of a bean in the application context
- BTo create a mock instance of a bean in the application context
- CTo replace a bean with a real instance in the application context
- DTo inject a mock instance into a service class
2.How does @SpringBootTest differ from @WebMvcTest in Spring Boot testing?
- A@SpringBootTest loads only the web layer, while @WebMvcTest loads the full application context
- B@SpringBootTest is used for testing repositories, while @WebMvcTest is for testing controllers
- C@SpringBootTest is used for unit tests, while @WebMvcTest is for integration tests
- D@SpringBootTest loads the full application context, while @WebMvcTest loads only the web layer
3.What is the role of the @ExtendWith annotation in JUnit 5?
- ATo integrate JUnit 5 with Spring TestContext Framework
- BTo ignore a test case conditionally
- CTo specify a custom test runner
- DTo declare a test as a parameterized test
4.Which Mockito feature allows you to verify that a method was called a specific number of times?
- Atimes()
- BverifyCount()
- CverifyTimes()
- DcallCount()
5.When using @DataJpaTest, which of the following is true?
- AIt is used for testing REST controllers
- BIt requires a running web server
- CIt loads the full application context
- DIt configures an in-memory database by default
6.In a Spring Boot test, what is the purpose of using @TestConfiguration?
- ATo configure a test database
- BTo define additional beans or override existing beans for testing
- CTo specify the test runner
- DTo load application properties for testing
7.How can you mock a static method using Mockito?
- AUsing Mockito.mockStatic()
- BUsing Mockito.whenStatic()
- CUsing Mockito.spyStatic()
- DUsing Mockito.mock()
8.What is the advantage of using @Mock over Mockito.mock() in Spring Boot tests?
- A@Mock allows for automatic injection into the application context
- B@Mock is faster than Mockito.mock()
- C@Mock supports mocking of static methods
- D@Mock provides better logging capabilities
9.Which annotation would you use to test a Spring Boot application with a specific profile?
- A@TestProfile
- B@Profile
- C@ProfileTest
- D@ActiveProfiles
10.What is the main benefit of using @SpyBean in a Spring Boot test?
- ATo create a mock instance of a bean
- BTo replace a bean with a real instance
- CTo partially mock a bean and retain its original behavior
- DTo inject a mock instance into a service class