Spring Questions and Answers – Integration Testing

«
»

This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer

Answer: a
Explanation: 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.
advertisement

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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: 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.
advertisement

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

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

advertisement

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: a
Explanation: 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.

advertisement

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
View Answer

Answer: a
Explanation: 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
View Answer

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

Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn