Spring Boot Testing: Intermediate JUnit & Mockito Mastery
Assess your skills in testing Spring Boot applications using JUnit and Mockito.
Questions in this quiz
12 questions on Spring Boot Testing: Intermediate JUnit & Mockito Mastery. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary purpose of using the @Mock annotation in a Spring Boot test?
- ATo inject dependencies into a class
- BTo create a mock instance of a class
- CTo create a real instance of a class
- DTo run tests in parallel
2.Which annotation is used to indicate that a method is a test method in JUnit 5?
- A@RunTest
- B@TestMethod
- C@JUnitTest
- D@Test
3.In a Spring Boot test, what does the @SpringBootTest annotation do?
- ALoads the full application context
- BRuns the test with a mock environment
- CLoads only the specified beans
- DRuns the test without loading any context
4.How do you verify that a method was called a specific number of times using Mockito?
- AcheckCallCount(method, 2)
- Bverify(method, times(2))
- Cvalidate(method, 2)
- DassertCalled(method, 2)
5.What is the role of the @InjectMocks annotation in Mockito?
- ATo inject mock dependencies into the tested class
- BTo initialize a real instance of a class
- CTo verify method calls
- DTo create a mock instance
6.Which of the following is a correct way to mock a repository in a Spring Boot test?
- A@Autowired MyRepository myRepository;
- B@Mock MyRepository myRepository;
- C@MockBean MyRepository myRepository;
- D@Mocked MyRepository myRepository;
7.What is the purpose of the @ExtendWith(SpringExtension.class) annotation in JUnit 5?
- ATo add more test cases dynamically
- BTo integrate Spring TestContext with JUnit 5
- CTo run tests in a Spring environment
- DTo extend a class with additional methods
8.Which Mockito method is used to stub a method call?
- Averify()
- Bmock()
- Cstub()
- Dwhen()
9.In a Spring Boot application, what is the purpose of the @DataJpaTest annotation?
- ATo test data access layers with an embedded database
- BTo test data access layers with a real database
- CTo test data access layers without loading any context
- DTo test data access layers with a full application context
10.How can you run a specific test method in a Spring Boot application using Maven?
- Amvn test -Dtest=TestClass#methodName
- Bmvn test -Dmethod=TestClass#methodName
- Cmvn test -Dexecute=TestClass#methodName
- Dmvn test -Drun=TestClass#methodName
11.What is the benefit of using @MockBean over @Mock in a Spring Boot test?
- A@MockBean creates a real bean
- B@MockBean integrates with the Spring context
- C@MockBean is faster than @Mock
- D@MockBean provides more detailed logs
12.Which annotation is used to specify that a test should be repeated a certain number of times in JUnit 5?
- A@RepeatedTest
- B@Repeat
- C@LoopTest
- D@TestRepeat