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).
advertisement

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.

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.
advertisement

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.

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).

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.
advertisement

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

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