This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “Hamcrest Matchers”.
1. ________________ is a library that contains a lot of helpful matcher objects , ported in several languages.
a) Java
b) Pygame
c) AllenWake
d) Hamcrest
View Answer
Explanation: Hamcrest is a library that contains a lot of helpful matcher objects (known also as constraints or predicates).
2. Hamcrest is not a ______________ framework in itself.
a) Matching
b) Testing
c) Asserting
d) Checking
View Answer
Explanation: Hamcrest helps you declaratively specify simple matching rules.
3. The package for the assertThat() function is?
a) org.hamcrest.CoreMatchers.assertThat
b) org.junit.Assert.assertThat
c) org.junit.JunitMatchers.assertThat
d) org.junit.hasItem.assertThat
View Answer
Explanation: The asserThat() function is a part of the main JUnit core assert functions.
4. ______________ Hamcrest matcher can be used to match absolutely everything.
a) Is
b) AnyOf
c) Anything
d) Not
View Answer
Explanation: Matches absolutely anything. Useful in some cases where one wants to make the assert statement more readable.
5. ______ is used only to improve the readability of the statements.
a) anything
b) is
c) sameInstance
d) nullValue
View Answer
Explanation: The Is Hamcrest matcher does not add any more functionality other than improving readability.
6. Which Hamcrest matcher is just like the && operator?
a) Is
b) Anything
c) sameInstance
d) allOf
View Answer
Explanation: Checks to see if all contained matchers match (just like the && operator).
7. ________ checks to see if any of the contained matchers match.
a) anyOf
b) allOf
c) instanceOf
d) notNull
View Answer
Explanation: The anyOf Hamcrest matcher is just like the || operator.
8. ___________ traverses the meaning of the contained matchers.
a) not
b) or
c) allOf
d) andAll
View Answer
Explanation: The not Hamcrest matcher is used to traverse the meaning of matchers contained in the argument.
9. The instanceOf matcher is equivalent to ________
a) isCompatibleType
b) isCompatible
c) isInstance
d) isSame
View Answer
Explanation: Match whether objects are of compatible type (are instances of one another).
10. ___________ is used to test object identity.
a) instanceOf
b) isCompatibleType
c) type
d) sameInstance
View Answer
Explanation: Checks whether it is the same instance of the object or not.
Sanfoundry Global Education & Learning Series – JUnit.
To practice all areas of Junit, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Computer Science Internship
- Check JUnit Books
- Check Programming Books
- Practice Programming MCQs