JUnit Questions and Answers – JUnit Test Runners

This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “JUnit Test Runners”.

1. JUnit runners are available in which package?
a) org.junit.runners
b) junitfiles.runners
c) org.runners
d) org.junit.files.runners
View Answer

Answer: a
Explanation: The default JUnit package is “org,junit”. Runners are found in “org,junit.runner”.

2. To start a test case as JUnit 3.8 test case which runner is required?
a) org.junit.runners.Junit4
b) org.junit.runners.Parameterized
c) org.junit.internal.runners.Junit38ClassRunner
d) org.junit.internal.runners.Junit4
View Answer

Answer: c
Explanation: This runner is included in the current release of JUnit only for backward compatibility. It will start the test case as a JUnit 3.8 test case.

3. What is a Façade in JUnit?
a) It is a group of test cases
b) It is a design pattern that provides a unified interface to a set of interfaces in a subsystem
c) It is a collection of superclasses
d) It is a group of mock objects

View Answer
Answer: b
Explanation: Façade defines a higher-level interface that makes the subsystem easier to use.

4. To create a custom test runner which class needs to be extended?
a) CustomRunner
b) TestRunner
c) Runner
d) UserRunner
View Answer

Answer: c
Explanation: The Runner class is an abstract class that needs to be extended to create a custom test runner.

5. What type of object is returned on completion of a test?
a) org.junit.runner.Result
b) org.junit.runner.Complete
c) org.junit.runner.Outcome
d) org.junit.runner.Object
View Answer

Answer: a
Explanation: An org.junit.runner.Result object collects and summarizes information from running multiple tests.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. To listen to events during a test, which class has to be extended?
a) org.junit.runner.notification.RunListener
b) org.junit.runner.Listener
c) org.junit.runner.notification.Listener
d) org.junit.runner.RunListener
View Answer

Answer: a
Explanation: To respond to events during a test run, RunListener is extended and the appropriate methods overridden. If a listener throws an exception during a test event, it is removed for the remainder of the test run.

7. When does the wasSuccessful() method of the Runner class return true?
a) The test file compiled
b) The test file ran
c) Some of the test cases ran successfully
d) All the test cases ran succesfully
View Answer

Answer: d
Explanation: wasSuccesful() method is a public method of the Runner class that returns true if and only if all tests succeeded.

8. To run the file TestClass.class from the command line, we have to type what?
a) java TestClass
b) javac TestClass
c) java org.junit.runner.JUnitCore TestClass
d) org.junit.runner.JUnitCore TestClass
View Answer

Answer: c
Explanation: The test cases are executed using JUnitCore class which is referenced by “org.junit.runner.JUnitCore”.

9. What does the getRunCount() method of the Result return?
a) String denoting the time of execution
b) Integer denoting the time of execution
c) int denoting the number of tests run
d) int denoting the number of failed tests
View Answer

Answer: c
Explanation: getRunCount() returns the number of tests run. GetRuntime() returns the execution time in milliseconds.

10. What information does an object of the Failure class contain?
a) Description of the failed test
b) Description of the failed test and the exception thrown while running it
c) Description of the fail() method
d) Description of the exception thrown
View Answer

Answer: b
Explanation: A failure contains an object of org.junit.runner.Description and the exception thrown while running the test case.

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]

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.