QuizzesSpring Boot Testing: Intermediate JUnit & Mockito Mastery
intermediate
spring

Spring Boot Testing: Intermediate JUnit & Mockito Mastery

Assess your skills in testing Spring Boot applications using JUnit and Mockito.

18 minutes 12 questions Pass at 70%
Time Limit
18 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

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. 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. 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. 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. 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. 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. 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. 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. 8.Which Mockito method is used to stub a method call?

    • Averify()
    • Bmock()
    • Cstub()
    • Dwhen()
  9. 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. 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. 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. 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