
- 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 II
Q 1 - Which of the following annotation causes that method run once after all tests have finished?
Answer : D
Explanation
Annotating a public static void method with @AfterClass cause that method run after all tests have finished. This can be used to perform clean-up activities.
Q 2 - Which of the following is correct about JUnit execution procedure?
A - First of all method annotated as @BeforeClass execute only once.
B - Lastly, the method annotated as @AfterClass executes only once.
C - Method annotated as @Before executes for each test case but before executing the test case.
Answer : D
Explanation
All of the above options are correct.
Q 3 - Which of the following is correct about JUnit execution procedure?
A - Method annotated as @After executes for each test case but after the execution of test case.
B - In between method annotated as @Before and method annotated as @After each test case executes.
Answer : C
Explanation
Method annotated as @After executes for each test case but after the execution of test case. In between method annotated as @Before and method annotated as @After each test case executes.
Q 4 - Which of the following is correct about org.junit.JUnitCore class?
A - The test cases are executed using JUnitCore class.
B - JUnitCore is a facade for running tests.
C - It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures.
Answer : D
Explanation
The test cases are executed using JUnitCore class. JUnitCore is a facade for running tests. It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures.
Q 5 - Which of the following is correct about org.junit.JUnitCore class?
A - The test cases are executed using JUnitCore class.
B - JUnitCore is a facade for running tests.
C - It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures.
Answer : D
Explanation
The test cases are executed using JUnitCore class. JUnitCore is a facade for running tests. It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures.
Q 6 - Which of the following method of Assert class checks that two primitives/Objects are equal?
A - void assertEquals(boolean expected, boolean actual)
B - void assert(boolean expected, boolean actual)
Answer : A
Explanation
void assertEquals(boolean expected, boolean actual) checks that two primitives/Objects are equal.
Q 7 - Which of the following method of Assert class checks that a condition is true?
A - void assert(boolean condition)
B - void assertTrue(boolean condition)
Answer : B
Explanation
void assertTrue(boolean condition) checks that a condition is true.
Q 8 - Which of the following method of Assert class checks that a condition is false?
A - void assert(boolean condition)
B - void assertFalse(boolean condition)
Answer : B
Explanation
void assertFalse(boolean condition) checks that a condition is false.
Q 9 - Which of the following method of Assert class checks that an object isn't null?
A - void assert(Object object, boolean toCheckAsNull)
B - void assertCheck(Object object, boolean toCheckAsNull)
Answer : C
Explanation
void assertNotNull(Object object) checks that an object isn't null.
Q 10 - Which of the following method of Assert class checks that an object is null?
A - void assert(Object object, boolean toCheckAsNull)
B - void assertCheck(Object object, boolean toCheckAsNull)
Answer : C
Explanation
void assertNull(Object object) checks that an object is null.
Q 11 - Which of the following method of Assert class checks if two object references point to the same object?
A - void assert(Object expected, Object actual)
B - void assertCheck(Object expected, Object actual)
Answer : C
Explanation
void assertSame(Object expected, Object actual) checks if two object references point to the same object.
Q 12 - Which of the following method of Assert class checks if two object references are not pointing to the same object?
A - void assert(Object expected, Object actual,boolean isSame)
B - void assertCheck(Object expected, Object actual,boolean isSame)
C - void assertNotSame(Object expected, Object actual)
D - void assertChecks(Object expected, Object actual,boolean isSame)
Answer : C
Explanation
void assertNotSame(Object expected, Object actual) checks if two object references are not pointing to the same object.
Q 13 - Which of the following method of Assert class checks whether two arrays are equal to each other?
A - void assert(Object[] expectedArray, Object[] resultArray,boolean isSame)
B - void assertCheck(Object[] expectedArray, Object[] resultArray,boolean isSame)
C - void assertArrayEquals(Object[] expectedArray, Object[] resultArray)
D - void assertChecks(Object[] expectedArray, Object[] resultArray,boolean isSame)
Answer : C
Explanation
void assertArrayEquals(expectedArray, resultArray) checks whether two arrays are equal to each other.
Q 14 - Which of the following method of Assert class fails a test with no message?
A - void assertChecks(boolean pass)
Answer : D
Explanation
void fail() fails a test with no message.
Q 15 - Which of the following method of TestCase class counts the number of test cases executed by run(TestResult result)?
Answer : A
Explanation
int countTestCases() method counts the number of test cases executed by run(TestResult result).
Q 16 - Which of the following method of TestCase class creates a default TestResult object?
A - TestResult getTestResult()
Answer : B
Explanation
TestResult createResult() method creates a default TestResult object.
Q 17 - Which of the following method of TestCase class gets the name of a TestCase?
Answer : C
Explanation
String getName() method gets the name of a TestCase.
Q 18 - Which of the following method of TestCase class runs a test, collecting the results with a default TestResult object?
Answer : D
Explanation
TestResult run() method runs a test, collecting the results with a default TestResult object.
Q 19 - Which of the following method of TestCase class runs the test case and collects the results in TestResult?
A - void runTestCase (TestResult result)
B - void runTest (TestResult result)
Answer : D
Explanation
void run (TestResult result) method runs the test case and collects the results in TestResult.
Q 20 - Which of the following method of TestCase class sets the name of a TestCase?
Answer : C
Explanation
void setName() method sets the name of a TestCase.
Q 21 - Which of the following method of TestCase class sets up the fixture, for example, open a network connection?
Answer : B
Explanation
void setUp() method sets up the fixture.
Q 22 - Which of the following method of TestCase class tears down the fixture, for example, close a network connection?
Answer : B
Explanation
void tearDown() method tears down the fixture.
Q 23 - Which of the following method of TestResult class adds an error to the list of errors?
A - void addError(Test test, Throwable t)
B - void addError(Test test, Error t)
Answer : A
Explanation
void addError(Test test, Throwable t) method adds an error to the list of errors.
Q 24 - Which of the following method of TestResult class adds a failure to the list of failures?
A - void addFailure(Test test, Error t)
B - void addFailure(Test test, AssertionFailedError t)
Answer : B
Explanation
void addFailure(Test test, AssertionFailedError t) method adds a failure to the list of failures.
Q 25 - Which of the following method of TestResult class informs the result that a test was completed?
Answer : C
Explanation
void endTest(Test test) method informs the result that a test was completed.
Answer Sheet
Question Number | Answer Key |
---|---|
1 | D |
2 | D |
3 | C |
4 | D |
5 | D |
6 | A |
7 | B |
8 | B |
9 | C |
10 | C |
11 | C |
12 | C |
13 | C |
14 | D |
15 | A |
16 | B |
17 | C |
18 | D |
19 | D |
20 | C |
21 | B |
22 | B |
23 | A |
24 | B |
25 | C |