250+ TOP MCQs on Integration Testing and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Integration Testing”.

1. Base class to access the managed application context through the inherited getApplicationContext() method.
a) AbstractSingleSpringContextTests
b) AbstractSingleSpring
c) Test context listener
d) Test execution listener

Answer: a
Clarification: With Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractSingleSpringContextTests base class to access the managed application context through the inherited getApplicationContext() method.

2. The TestContext framework provides two test execution listeners related to context management:-
a) DependencyInjectionTestExecutionListener
b) DirtiesContextTestExecutionListener
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: They will be registered with a test context manager by default if you don’t specify your own explicitly.
• DependencyInjectionTestExecutionListener: This injects dependencies, including
the managed application context, into your tests.
• DirtiesContextTestExecutionListener: This handles the @DirtiesContext
annotation and reloads the application context when necessary.

3. Interface which can provide access to the managed application context through the protected field applicationContext
a) ApplicationContextAware
b) ApplicationContext
c) ApplicationContextAwareContext
d) None of the mentioned

Answer: a
Clarification: These classes integrate with a test context manager and implement the ApplicationContextAware interface, so they can provide access to the managed application context through the protected field applicationContext.

4. In JUnit 4, you can simply run your test with the test runner SpringJUnit4ClassRunner.
a) True
b) False

Answer: a
Clarification: In JUnit 4, you can simply run your test with the test runner SpringJUnit4ClassRunner to have a test context manager integrated. However, in TestNG, you have to integrate with a test context manager manually.

5. Method to indicate that the application context is dirty.
a) getDirty()
b) setDirty()
c) all of the mentioned
d) none of the mentioned

Answer: b
Clarification: You can call the setDirty() method to indicate that the application context is dirty so that it will be reloaded automatically for the next test method.

6. In JUnit4, to explicitly specify a Spring-specific test runner for running your test.
a) SpringJUnit4ClassRunner
b) SpringJUnit4Class
c) SpringJUnit4
d) None of the mentioned

Answer: a
Clarification: You have to explicitly specify a Spring-specific test runner for running your test—SpringJUnit4ClassRunner.

7. Annotation for SpringJUnit4ClassRunner:-
a) @Run
b) @RunWith
c) All of the mentioned
d) None of the mentioned

Answer: b
Clarification: For this option, you have to explicitly specify a Spring-specific test runner for running your test—SpringJUnit4ClassRunner. You can specify this in the @RunWith annotation at the class level.

8. This class implements the ApplicationContextAware interface, so you can get access to the managed application context:-
a) AbstractJUnit38SpringContext
b) AbstractJUnit38Spring
c) AbstractJUnit38SpringContextTests
d) None of the mentioned

Answer: c
Clarification: This class implements the ApplicationContextAware interface, so you can get access to the managed application context via the protected field applicationContext.

9. AbstractJUnit38SpringContext class also implements the ApplicationContextAware interface.
a) True
b) False

Answer: b
Clarification: AbstractTestNGSpringContextTests class also implements the ApplicationContextAware interface.

10. Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the:-
a) AbstractDependencyInjectionSpringContextTests
b) AbstractSingleSpringContextTests
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: When using Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractDependencyInjectionSpringContextTests base class, which is a subclass of AbstractSingleSpringContextTests, to have its test fixtures injected automatically.

11. AbstractDependencyInjectionSpringContextTests supports dependency injection.
a) auto-wires beans by type via setter methods
b) auto-wires beans by name via protected fields
c) none of the mentioned
d) all of the mentioned

Answer: c
Clarification: When using Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractDependencyInjectionSpringContextTests base class, which is a subclass of AbstractSingleSpringContextTests, to have its test fixtures injected automatically.

12. Test fixtures injected from the managed application context by annotating:-
a) @Autowired
b) @Resource
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: When using the TestContext framework to create tests, you can have their test fixtures injected from the managed application context by annotating a field or setter method with the @Autowired or @Resource annotations.

13. TestContext support class AbstractJUnit4SpringContextTests, you can also have test fixtures injected from the managed application context.
a) True
b) False

Answer: a
Clarification: By extending the TestContext support class AbstractJUnit4SpringContextTests, you can also have test fixtures injected from the managed application context. In this case, you don’t need to specify SpringJUnit4ClassRunner for your test, as it is inherited from the parent.

14. Starting from Spring 2.5, the TestContext framework provides a test execution listener related to transaction management:-
a) TransactionalTestExecutionListener
b) TransactionalTestExecution
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: It will be registered with a test context manager by default if you don’t specify your own explicitly.

15. Annotation for TransactionalTestExecutionListener:-
a) @Transactional
b) @RunWith
c) @Run
d) None of the mentioned

Answer: a
Clarification: TransactionalTestExecutionListener: This handles the @Transactional annotation at the class or method level and has the methods run within transactions automatically.

Leave a Reply

Your email address will not be published. Required fields are marked *