JUnit Questions and Answers – Need for Unit Tests

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

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

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

Answer: a
Explanation: JUnitMatchers manipulates the default Java objects and thus, extends java.lang.Object.
advertisement
advertisement

4. _________ is used for combining those matchers which must both pass.
a) all
b) both
c) justTwo
d) matchTwo
View Answer

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

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

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

Answer: d
Explanation: Public setter and getter methods are required for Properties to be defined in JavaBeans classes.
advertisement

8. A/An __________ property is an array instead of a single value.
a) Indexed
b) valued
c) null
d) variable
View Answer

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

Answer: b
Explanation: equalToIgnoringCase is a core Hamcrest Matcher which tests given string equality.
advertisement

10. _________ tests whether a given Map has a given entry.
a) hasItem
b) hasItems
c) hasValue
d) hasEntry
View Answer

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

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.