This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses on “Unit Testing Spring”.
1. This encapsulates the context of a test’s execution:-
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener
View Answer
Explanation: This encapsulates the context of a test’s execution, including the application context, test class, current test instance, current test method, and current test exception.
2. This manages a test context for a test and triggers test execution listeners:-
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener
View Answer
Explanation: This manages a test context for a test and triggers test execution listeners at predefined test execution points, including when preparing a test instance, before executing a test method (before any framework-specific initialization methods), and after executing a test method (after any framework-specific cleanup methods).
3. This defines a listener interface; by implementing this, you can listen to test execution events.
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener
View Answer
Explanation: The TestContext framework provides several test execution listeners for common testing features, but you are free to create your own.
4. Spring provides convenient TestContext support classes for:-
a) JUnit3
b) JUnit4
c) TestNG5
d) All of the mentioned
View Answer
Explanation: Spring provides convenient TestContext support classes for JUnit 3, JUnit 4, and TestNG 5, with particular test execution listeners pre registered.
5. JUnit 4 allows you to annotate your test methods with:-
a) @Test
b) @Autowire
c) @JTest
d) None of the mentioned
View Answer
Explanation: JUnit 4 allows you to annotate your test methods with JUnit @Test annotation, so an arbitrary public method can be run as a test case.
6. Usually, a test and its target class are located in the same package, but the source files of tests are stored in a separate directory.
a) True
b) False
View Answer
Explanation: (e.g., test) from the source files of other classes (e.g., src).
7. Method to perform cleanup tasks:-
a) finalize
b) tearDown
c) all of the mentioned
d) none of the mentioned
View Answer
Explanation: You can override the tearDown() method to perform cleanup tasks, such as releasing permanent resources.
8. The static assert methods is declared in the:-
a) org.junit.Assert
b) org.junit.*
c) all of the mentioned
d) none of the mentioned
View Answer
Explanation: You can override the tearDown() method to perform cleanup tasks, such as releasing permanent resources.
9. Attribute which specifies the exception type:-
a) after
b) expected
c) before
d) test
View Answer
Explanation: JUnit 4 offers a powerful feature that allows you to expect an exception to be thrown in a test case. You can simply specify the exception type in the expected attribute of the @Test annotation.
10. Test data sets are provided by data providers, which are methods with the:-
a) @DataProvider
b) @Autowire
c) @JTest
d) None of the mentioned
View Answer
Explanation: In TestNG, test data sets are provided by data providers, which are methods with the @DataProvider annotation.
11. An object that simulates a dependent object:-
a) stub
b) mock
c) test
d) none of the mentioned
View Answer
Explanation: A stub is an object that simulates a dependent object with the minimum number of methods required for a test.
12. An Object which usually knows how its methods are expected to be called:-
a) stub
b) mock
c) test
d) none of the mentioned
View Answer
Explanation: In contrast to a stub, a mock object usually knows how its methods are expected to be called in a test.
13. Libraries that can help create mock objects:-
a) EasyMock
b) jMock
c) All of the mentioned
d) None of the mentioned
View Answer
Explanation: In Java, there are several libraries that can help create mock objects, including EasyMock and jMock.
14. Test used to test several units in combination as a whole.
a) Integration tests
b) JUnit4
c) TestNG5
d) All of the mentioned
View Answer
Explanation: Integration tests, in contrast, are used to test several units in combination as a whole.
15. Spring supports web controller testing by providing Servlet API:-
a) MockHttpServletRequest
b) MockHttpServletResponse
c) MockHttpSession
d) All of the mentioned
View Answer
Explanation: Spring supports web controller testing by providing a set of mock objects for the Servlet API (including MockHttpServletRequest, MockHttpServletResponse, and MockHttpSession).
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.
- Apply for Programming Internship
- Check Information Technology Books
- Practice Programming MCQs
- Check Spring Books