This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “JUnit Test Runners”.
1. JUnit runners are available in which package?
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?
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
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?
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?
Explanation: An org.junit.runner.Result object collects and summarizes information from running multiple tests.
6. To listen to events during a test, which class has to be extended?
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
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
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
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
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.