JUnit Questions and Answers – Hamcrest Matchers

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

Answer: d
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

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

Answer: b
Explanation: The asserThat() function is a part of the main JUnit core assert functions.
advertisement
advertisement

4. ______________ Hamcrest matcher can be used to match absolutely everything.
a) Is
b) AnyOf
c) Anything
d) Not
View Answer

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

Answer: b
Explanation: The Is Hamcrest matcher does not add any more functionality other than improving readability.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Which Hamcrest matcher is just like the && operator?
a) Is
b) Anything
c) sameInstance
d) allOf
View Answer

Answer: d
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

Answer: a
Explanation: The anyOf Hamcrest matcher is just like the || operator.
advertisement

8. ___________ traverses the meaning of the contained matchers.
a) not
b) or
c) allOf
d) andAll
View Answer

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

Answer: a
Explanation: Match whether objects are of compatible type (are instances of one another).
advertisement

10. ___________ is used to test object identity.
a) instanceOf
b) isCompatibleType
c) type
d) sameInstance
View Answer

Answer: d
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.