QuizzesSpring Boot Testing: Introduction to JUnit & Mockito
beginner
spring

Spring Boot Testing: Introduction to JUnit & Mockito

A beginner's quiz on testing Spring Boot applications using JUnit and Mockito.

15 minutes 15 questions Pass at 70%
Time Limit
15 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

15 questions on Spring Boot Testing: Introduction to JUnit & Mockito. Work through them here, then start the quiz to answer them and see your score.

  1. 1.What is the primary purpose of JUnit in Spring Boot applications?

    • ATo manage database connections
    • BTo configure application properties
    • CTo perform unit testing
    • DTo handle HTTP requests
  2. 2.Which annotation is used to denote a test method in JUnit?

    • A@Mock
    • B@RunWith
    • C@Test
    • D@SpringBootTest
  3. 3.What is the role of Mockito in testing?

    • ATo create mock objects
    • BTo compile Java code
    • CTo manage application security
    • DTo deploy applications
  4. 4.Which annotation is used to inject a mock object into a Spring Boot test?

    • A@InjectMocks
    • B@Component
    • C@Autowired
    • D@MockBean
  5. 5.How do you verify a method was called in Mockito?

    • Acheck(methodName)
    • Bconfirm(methodName)
    • Cverify(methodName)
    • DassertCalled(methodName)
  6. 6.What does the @SpringBootTest annotation do?

    • AIt starts the entire Spring context for integration testing.
    • BIt configures the database connection.
    • CIt mocks all dependencies automatically.
    • DIt sets up security configurations.
  7. 7.Which Mockito method is used to stub a method call?

    • Astub()
    • Bwhen()
    • Cmock()
    • Dgiven()
  8. 8.What is the purpose of the @Mock annotation?

    • ATo create a mock object
    • BTo configure the database
    • CTo inject dependencies
    • DTo run tests in parallel
  9. 9.Which JUnit annotation is used to run a block of code before each test?

    • A@AfterEach
    • B@AfterAll
    • C@BeforeAll
    • D@BeforeEach
  10. 10.What is the purpose of the @InjectMocks annotation in Mockito?

    • ATo create a new mock object
    • BTo run tests in a specific order
    • CTo configure the application context
    • DTo inject mock objects into the tested class
  11. 11.Which of the following is true about unit tests?

    • AThey are slower than integration tests.
    • BThey test individual components in isolation.
    • CThey test the entire application flow.
    • DThey require a live database connection.
  12. 12.What is the primary benefit of using mock objects in testing?

    • ATo enhance security
    • BTo automatically generate documentation
    • CTo isolate the unit of work being tested
    • DTo speed up the deployment process
  13. 13.Which annotation is used to specify that a test method should be executed with a specific runner?

    • A@TestRunner
    • B@RunWith
    • C@ExecuteWith
    • D@SpringRunner
  14. 14.What does the assertEquals() method do in a JUnit test?

    • AVerifies a method call
    • BChecks if two values are equal
    • CInitializes the test environment
    • DMocks a method
  15. 15.How can you run only a specific test class in a Spring Boot application?

    • AUse the @RunSpecific annotation
    • BModify the application.properties file
    • CUse the command 'mvn test -Dtest=ClassName'
    • DChange the main class of the application