This set of JUnit Quiz focuses on “Need for Unit Tests”.
1. The JUnit hasItem() function is a _____________
a) Hamcrest Matcher
b) Instance Function
c) JUnitMatcher
d) Matcher
View Answer
Explanation: hasItem() is a useful matcher with for use with the assertThat method.
2. The package to which hasItem() function belongs is _______________
a) org.junit.JUnitMatchers.hasItem
b) org.junit.hasItem
c) org.junit.Junit.hasItem
d) org.junit.hamcrest.hasItem
View Answer
Explanation: The hasItem() is a JUnitMatcher.
3. Class JUnitMatchers extends _______________
a) java.lang.Object
b) java.lang.String
c) java.util.*
d) java.util.Arrays
View Answer
Explanation: JUnitMatchers manipulates the default Java objects and thus, extends java.lang.Object.
4. _________ is used for combining those matchers which must both pass.
a) all
b) both
c) justTwo
d) matchTwo
View Answer
Explanation: The both function is a part of the internal Combinable matchers of JUnit.
5. __________ Hamcrest matcher tests for null values.
a) isNull
b) nullValue
c) isNullValue
d) isNullable
View Answer
Explanation: The nullValue function is defined to detect null valued objects.
6. ___________ tests whether a JavaBean has a particular property.
a) isProperty
b) porperty
c) hasProperty
d) isPresent
View Answer
Explanation: The hasProperty is a core Hamcrest matcher.
7. To define a ________ in a JavaBean class, public getter and setter methods have to be supplied.
a) Class
b) Object
c) Value
d) Property
View Answer
Explanation: Public setter and getter methods are required for Properties to be defined in JavaBeans classes.
8. A/An __________ property is an array instead of a single value.
a) Indexed
b) valued
c) null
d) variable
View Answer
Explanation: In such cases, the bean class is responsible for providing methods for setting and getting everything.
9. __________________ tests whether a given string equals another one, ignoring the case.
a) stringEqual
b) equalToIgnoringCase
c) ignoringCaseEqual
d) equalToCase
View Answer
Explanation: equalToIgnoringCase is a core Hamcrest Matcher which tests given string equality.
10. _________ tests whether a given Map has a given entry.
a) hasItem
b) hasItems
c) hasValue
d) hasEntry
View Answer
Explanation: Testing the map for a given entry can only be done using the hasEntry method.
Sanfoundry Global Education & Learning Series – JUnit.
To practice all areas of JUnit for Quizzes, 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]
- Practice Programming MCQs
- Check JUnit Books
- Apply for Computer Science Internship
- Check Programming Books