Spring Boot Testing: Introduction to JUnit & Mockito
A beginner's quiz on testing Spring Boot applications using JUnit and Mockito.
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.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.Which annotation is used to denote a test method in JUnit?
- A@Mock
- B@RunWith
- C@Test
- D@SpringBootTest
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.Which annotation is used to inject a mock object into a Spring Boot test?
- A@InjectMocks
- B@Component
- C@Autowired
- D@MockBean
5.How do you verify a method was called in Mockito?
- Acheck(methodName)
- Bconfirm(methodName)
- Cverify(methodName)
- DassertCalled(methodName)
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.Which Mockito method is used to stub a method call?
- Astub()
- Bwhen()
- Cmock()
- Dgiven()
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.Which JUnit annotation is used to run a block of code before each test?
- A@AfterEach
- B@AfterAll
- C@BeforeAll
- D@BeforeEach
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.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.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.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.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.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