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 III

Q 1 - Which of the following method of TestResult class gets the number of detected errors?

A - int getErrors()

B - int errorCount()

C - int countErrors()

D - int getErrorCount()

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

C - Enumeration<TestFailure> getErrors()

D - Enumeration<Object> getErrors()

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?

A - int error()

B - int errorCount()

C - int failureCount()

D - int failure()

Answer : C

Explanation

int failureCount() method gets the number of detected failures.

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?

A - int testCount()

B - int runCount()

C - int countExecutions()

D - int countRun()

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?

A - void startTest(Test test)

B - void start(Test test)

C - void execute(Test test)

D - void executeTest(Test test)

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?

A - void stopTest()

B - void stop()

C - void stopTest(Test test)

D - void breakTest(Test test)

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?

A - void add(Test)

B - void add()

C - void addTest(Test test)

D - void addTestCase(Test test)

Answer : C

Explanation

void addTest(Test test) method adds a test to the suite.

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?

A - int countTestExecutions()

B - int countTest()

C - int count()

D - int countTestCases()

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?

A - String getNameOfTestSuite()

B - String getTestName()

C - String getName()

D - String getTestSuite()

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)

C - void run(TestResult result)

D - void executeTest(TestResult result)

Answer : C

Explanation

void run(TestResult result) method runs the tests and collects their result in a TestResult.

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?

A - Test testAt(int index)

B - Test testAtIndex(int index)

C - Test getTestAt(int index)

D - Test test(int 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?

A - int testCount()

B - int testCaseCount()

C - int getTestCount()

D - int testSuiteCount()

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)

C - static Test getWarning(String message)

D - static Test warning(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.

A - true

B - false

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.

A - false

B - true

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.

A - false

B - true

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.

A - false

B - true

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.

A - false

B - true

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.

A - false

B - true

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?

A - JUnitCore

B - TestCase

C - TestSuite

D - TestResult

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?

A - JUnitCore

B - TestCase

C - TestSuite

D - TestResult

Answer : C

Explanation

Test suite means bundle a few unit test cases and run it together.

Q 25 - @RunWith and @Suite annotation are used to run the suite test.

A - false

B - true

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