
- JUnit Tutorial
- JUnit - Home
- JUnit - Overview
- JUnit - Environment Setup
- JUnit - Test Framework
- JUnit - Basic Usage
- JUnit - API
- JUnit - Writing a Tests
- JUnit - Using Assertion
- JUnit - Execution Procedure
- JUnit - Executing Tests
- JUnit - Suite Test
- JUnit - Ignore Test
- JUnit - Time Test
- JUnit - Exceptions Test
- JUnit - Parameterized Test
- JUnit - Plug with Ant
- JUnit - Plug with Eclipse
- JUnit - Extensions
- JUnit Useful Resources
- JUnit - Questions and Answers
- JUnit - Quick Guide
- JUnit - Useful Resources
- JUnit - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JUnit Mock Test
This section presents you various set of Mock Tests related to JUnit Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

JUnit Mock Test III
Q 1 - Which of the following method of TestResult class gets the number of detected errors?
Answer : B
Explanation
int errorCount() method gets the number of detected errors.
Q 2 - Which of the following method of TestResult class returns an Enumeration for the errors?
A - Enumeration<Object> errors()
B - Enumeration<TestFailure> errors()
Answer : C
Explanation
Enumeration<TestFailure> errors() method returns an Enumeration for the errors.
Q 3 - Which of the following method of TestResult class gets the number of detected failures?
Answer : C
Explanation
int failureCount() method gets the number of detected failures.
Q 4 - Which of the following method of TestResult class runs a TestCase?
B - void execute(TestCase test)
Answer : A
Explanation
void run(TestCase test) method runs a TestCase.
Q 5 - Which of the following method of TestResult class gets the number of run tests?
Answer : B
Explanation
int runCount() method gets the number of run tests.
Q 6 - Which of the following method of TestResult class informs the result that a test will be started?
Answer : A
Explanation
void startTest(Test test) method informs the result that a test will be started.
Q 7 - Which of the following method of TestResult class marks that the test run should stop?
Answer : B
Explanation
void stop() method marks that the test run should stop.
Q 8 - Which of the following method of TestSuite class adds a test to the suite?
Answer : C
Explanation
void addTest(Test test) method adds a test to the suite.
Q 9 - Which of the following method of TestSuite class adds the tests from the given class to the suite?
A - void addTest(Class<? extends TestCase> testClass)
B - void addTestSuite(Class<? extends TestCase> testClass)
Answer : B
Explanation
void addTestSuite(Class<? extends TestCase> testClass) method adds the tests from the given class to the suite.
Q 10 - Which of the following method of TestSuite class counts the number of test cases that will be run by this test?
Answer : D
Explanation
int countTestCases() method counts the number of test cases that will be run by this test.
Q 11 - Which of the following method of TestSuite class returns the name of the suite?
Answer : C
Explanation
String getName() method returns the name of the suite.
Q 12 - Which of the following method of TestSuite class runs the tests and collects their result in a TestResult?
A - void execute(TestResult result)
B - void runTest(TestResult result)
Answer : C
Explanation
void run(TestResult result) method runs the tests and collects their result in a TestResult.
Q 13 - Which of the following method of TestSuite class sets the name of the suite?
A - void setSuiteName(String name)
Answer : B
Explanation
void setName(String name) method sets the name of the suite.
Q 14 - Which of the following method of TestSuite class returns the test at the given index?
Answer : A
Explanation
Test testAt(int index) method returns the test at the given index.
Q 15 - Which of the following method of TestSuite class returns the number of tests in this suite?
Answer : A
Explanation
int testCount() method returns the number of tests in this suite.
Q 16 - Which of the following method of TestSuite class returns a test which will fail and log a warning message?
A - static Test displayWarning(String message)
B - static Test showWarning(String message)
Answer : D
Explanation
int testCount() method returns a test which will fail and log a warning message.
Q 17 - The @Test annotation tells JUnit that the public void method to which it is attached can be run as a test case.
Answer : A
Explanation
The @Test annotation tells JUnit that the public void method to which it is attached can be run as a test case.
Q 18 - Annotating a public void method with @Before causes that method to be run before each Test method.
Answer : B
Explanation
Annotating a public void method with @Before causes that method to be run before each Test method.
Q 19 - Annotating a public void method with @After causes that method to be run after each Test method.
Answer : B
Explanation
Annotating a public void method with @After causes that method to be run after each Test method.
Q 20 - Annotating a public void method with @BeforeClass causes that method to be run before each Test method.
Answer : A
Explanation
Annotating a public static void method with @BeforeClass causes it to be run once before any of the test methods in the class.
Q 21 - Annotating a public void method with @AfterClass causes that method to be run after each Test method.
Answer : A
Explanation
@AfterClass will perform the method after all tests have finished. This can be used to perform clean-up activities.
Q 22 - The @Ignore annotation is used to ignore the test and that test will not be executed.
Answer : B
Explanation
The @Ignore annotation is used to ignore the test and that test will not be executed.
Q 23 - Which of the following class is used to run test cases?
Answer : A
Explanation
The test cases are executed using JUnitCore class.
Q 24 - Which of the following class is used to bundle unit test cases and run them together?
Answer : C
Explanation
Test suite means bundle a few unit test cases and run it together.
Answer : B
Explanation
Both @RunWith and @Suite annotation are used to run the suite test.
Answer Sheet
Question Number | Answer Key |
---|---|
1 | B |
2 | C |
3 | C |
4 | A |
5 | B |
6 | A |
7 | B |
8 | C |
9 | B |
10 | D |
11 | C |
12 | C |
13 | B |
14 | A |
15 | A |
16 | D |
17 | A |
18 | B |
19 | B |
20 | A |
21 | A |
22 | B |
23 | A |
24 | C |
25 | B |