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
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
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
Explanation: 1.0-0.03 = 0.97>0.03, hence is false.
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
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
Explanation: The TypeSafeMatcher is a useful base class for Matchers that require non-null values of a specific type.
6. The ___________ method of the TypeSafeMatcher class is made final.
a) matches
b) matchesSafely
c) describeMismatchSafely
d) No mehtod
View Answer
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
Explanation: This interface dictates the ability of an object to describe what it does.
8. The ____________ matcher checks if a given key is in a map.
a) hasEntry
b) hasValue
c) hasKey
d) isKey
View Answer
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
Explanation: The Matcher interface describes all methods needed to write custom matchers, which override the Matcher methods.
10. ___________ is the base class for all Matcher implementations.
a) MatcherBase
b) Base
c) Matcher
d) BaseMatcher
View Answer
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.
- Practice Programming MCQs
- Apply for Computer Science Internship
- Check Programming Books
- Check JUnit Books