This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “Ant”.
1. Mocks are Trojan horses because they replace real ___________ from the inside, without the calling classes being aware of it.
a) Methods
b) Objects
c) Variables
d) Classes
View Answer
Explanation: Mocks have access to internal information about the class, making them quite powerful.
2. When we’re talking about mock objects, a/an _________ is a feature built into the mock that verifies whether the external class calling this mock has the correct behavior.
a) Expectation
b) Explanation
c) Behavior
d) Amorous
View Answer
Explanation: For example, a database connection mock could verify that the close method on the connection is called exactly once during any test that involves code using this mock.
3. EasyMock instantiates an object based on an interface or class.
a) True
b) False
View Answer
Explanation: EasyMock is used to make mock objects which is based on the interface or class being called or extended.
4. EasyMock relies heavily on the __________import feature of Java.
a) Dynamic
b) Static
c) Class
d) Object
View Answer
Explanation: All EasyMock imports are static imports.
5. To use the createMock method of EasyMock we need to import ___________
a) org.easymock.EasyMock.createMock
b) org.EasyMock.createMock
c) org.easymock.createMock
d) org.createMock
View Answer
Explanation: The EasyMock methods are found under “org.easymock.EasyMock.*”.
6. __________ method creates a mock object that implements the given interface, order checking is enabled by default.
a) createNiceControl
b) createMockBuilder
c) createNiceMock
d) createStrictMock
View Answer
Explanation: createStrictMock is the old version of strictMock(String, Class), which is more completion friendly.
7. ___________ is used for the creation of a mock object, with the specification of it being of the requested type, which has implementations of the given interface or extends the given class.
a) createMock(Class<T> toMock)
b) createMock(MockType type, Class<T> toMock)
c) createMock(String name, Class<T>toMock)
d) createMock(String name, MockType type, Class<T>toMock)
View Answer
Explanation: createMock(MockType type, Class<T> toMock) is the old version of mock(MockType, Class), which is more completion friendly.
8. __________________ creates a mock object, of the requested type and name which are passed, which also has implementations of the given interface or extends the given class.
a) createMock(Class <T> toMock)
b) createMock(MockType type, Class<T> toMock)
c) createMock(String name, Class<T> toMock)
d) createMock(String name, MockType type, Class<T> toMock)
View Answer
Explanation: The name is passed as a parameter in the function definition.
9. ______________ creates a mock object that implements the given interface with the specification is that order checking is disabled by default.
a) createMock(Class<T> toMock)
b) createMock(MockType type, Class<T>toMock)
c) createMock(String name, Class<T> toMock)
d) createMock(String name, MockType type, Class<T> toMock)
View Answer
Explanation: The type parameter is the interface that the mock object should implement.
10. createMock(String name, Class<T> toMock) throws _________________ exception.
a) IndexOutOfBounds
b) IllegalArgumentException
c) NullPointer
d) Arithmetic
View Answer
Explanation: This exception is thrown when the name is not a valid Java identifier.
Sanfoundry Global Education & Learning Series – JUnit.
To practice all areas of Junit, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Practice Programming MCQs
- Apply for Computer Science Internship
- Check JUnit Books
- Check Programming Books