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.

Questions and Answers

JUnit Mock Test II

Q 1 - Which of the following annotation causes that method run once after all tests have finished?

A - @Test

B - @After

C - @BeforeClass

D - @AfterClass

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.

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.

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.

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.

Answer : A

Explanation

void assertEquals(boolean expected, boolean actual) checks that two primitives/Objects are equal.

Answer : B

Explanation

void assertTrue(boolean condition) checks that a condition is true.

Answer : B

Explanation

void assertFalse(boolean condition) checks that a condition is false.

Answer : C

Explanation

void assertNotNull(Object object) checks that an object isn't null.

Answer : C

Explanation

void assertNull(Object object) checks that an object is null.

Answer : C

Explanation

void assertSame(Object expected, Object actual) checks if two object references point to the same object.

Answer : C

Explanation

void assertNotSame(Object expected, Object actual) checks if two object references are not pointing to the same object.

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)

B - void assertCheck(boolean pass)

C - void assert(boolean pass)

D - void fail()

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)?

A - int countTestCases()

B - int executedTestCases()

C - int getTestCaseCount()

D - int testCases()

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()

B - TestResult createResult()

C - TestResult getTestResultInstance()

D - TestResult testResult()

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?

A - String getTestName()

B - String getNameOfTest()

C - String getName()

D - String getTestCase()

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?

A - TestResult runTestCase()

B - TestResult runTest()

C - TestResult runTestAndSave()

D - TestResult run()

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)

C - void runTestAndSave (TestResult result)

D - void run (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?

A - void setTestName()

B - void setNameOfTest()

C - void setName()

D - void setTestCase()

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?

A - void setTestName()

B - void setUp()

C - void setUpFixture()

D - void setTestCase()

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?

A - void tearDownTestName()

B - void tearDown()

C - void tearDownFixture()

D - void tearDownTestCase()

Answer : B

Explanation

void tearDown() method tears down the fixture.

Answer : A

Explanation

void addError(Test test, Throwable t) method adds an error to the list of errors.

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?

A - void showResult(Test test)

B - void getResult(Test test)

C - void endTest(Test test)

D - void startTest(Test test)

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
junit_questions_answers.htm
Advertisements