JUnit Questions and Answers – Integration Software Testing

This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “Integration Software Testing”.

1. Which Hamcrest core matcher checks if a number is equal to a number of some acceptable error?
a) closeTo
b) equals
c) errorBy
d) similarTo
View Answer

Answer: a
Explanation: Test whether given numbers are close to a given value.

2. assertThat(1.03, is(closeTo(1.0, 0.03))) is ____________
a) True
b) False
c) Null
d) Error
View Answer

Answer: a
Explanation: 1.0 + 0.03 is 1.03 which is the first value.

3. assertThat(0.03, is(closeTo(1.0, 0.03))) is ___________
a) True
b) False
c) Null
d) Error
View Answer

Answer: b
Explanation: 1.0-0.03 = 0.97>0.03, hence is false.
advertisement
advertisement

4. The closeTo function is found under which package?
a) org.hamcrest.TypeSafeMatcher
b) org.hamcrest.BaseMatcher
c) org.hamcrest.number.IsCloseTo
d) org.hamcrest.number.CloseTo
View Answer

Answer: c
Explanation: The closeTo function is actually a method of the isCloseTo class of Hamcrest.

5. The isCloseTo class extends which base class?
a) Matcher
b) HamcrestCore
c) TypeMatcher
d) TypeSafeMatcher
View Answer

Answer: d
Explanation: The TypeSafeMatcher is a useful base class for Matchers that require non-null values of a specific type.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. The ___________ method of the TypeSafeMatcher class is made final.
a) matches
b) matchesSafely
c) describeMismatchSafely
d) No mehtod
View Answer

Answer: a
Explanation: The matches method made final to prevent accidental override.

7. The TypeSafeMatcher implements the __________ interface.
a) Self
b) Describing
c) EqulityCheck
d) SelfDescribing
View Answer

Answer: d
Explanation: This interface dictates the ability of an object to describe what it does.
advertisement

8. The ____________ matcher checks if a given key is in a map.
a) hasEntry
b) hasValue
c) hasKey
d) isKey
View Answer

Answer: c
Explanation: The hasKey matcher checks if the particular key is present in the map.

9. To write custom matcher _____________ has to be implemented.
a) Matcher Interface
b) Hamcrest Interface
c) HamcrestMatching Interface
d) Not possible to implement
View Answer

Answer: b
Explanation: The Matcher interface describes all methods needed to write custom matchers, which override the Matcher methods.
advertisement

10. ___________ is the base class for all Matcher implementations.
a) MatcherBase
b) Base
c) Matcher
d) BaseMatcher
View Answer

Answer: d
Explanation: The BaseMatcher class is extended in every matcher subclass.

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.