JUnit Mock Test


Advertisements


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 I

Answer : A

Explanation

Testing is the process of checking the functionality of the application whether it is working as per requirements.

Answer : B

Explanation

Unit testing is the testing of single entity (class or method).

Answer : C

Explanation

Since test cases are executed by human resources so it is very slow and tedious and as test cases need to be executed manually so more testers are required in manual testing.

Answer : C

Explanation

Manual testing is less reliable as tests may not be performed with precision each time because of human errors. No programming can be done to write sophisticated tests which fetch hidden information.

Answer : C

Explanation

Automation runs test cases significantly faster than human resources. Test cases are executed by using automation tool so less tester are required in automation testing.

Answer : C

Explanation

Automation tests perform precisely same operation each time they are run. Testers can program sophisticated tests to bring out hidden information.

Answer : D

Explanation

All of the above options are correct.

Answer : C

Explanation

JUnit provides Test runners for running tests. JUnit tests can be run automatically and they check their own results and provide immediate feedback.

Answer : C

Explanation

JUnit tests can be organized into test suites containing test cases and even other test suites. JUnit shows test progress in a bar that is green if test is going fine and it turns red when a test fails in eclipse.

Answer : C

Explanation

There must be at least two unit test cases for each requirement: one positive test and one negative test. If a requirement has sub-requirements, each sub-requirement must have at least two test cases as positive and negative.

Answer : A

Explanation

Unit Tests are to be written before the code during development in order to help coders write the best code.

Q 13 - Which of the following tools provides JUnit integration?

A - Eclipse

B - Ant

C - Maven

D - All of the above.

Answer : D

Explanation

All of the above tools provides JUnit integration.

Answer : C

Explanation

Fixture is a fixed state of a set of objects used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.

Answer : C

Explanation

Fixture includes setUp() method which runs before every test invocation and tearDown() method which runs after every test method.

Answer : C

Explanation

Test suite means bundle a few unit test cases and run it together. In JUnit, both @RunWith and @Suite annotation are used to run the suite test.

Answer : A

Explanation

Test runner is used for executing the test cases.

Q 18 - Which of the following class contains a set of assert methods?

A - Assert

B - TestCase

C - TestResult

D - TestSuite

Answer : A

Explanation

Assert class contains a set of assert methods.

Q 19 - Which of the following class contains a test case and defines the fixture to run multiple tests?

A - Assert

B - TestCase

C - TestResult

D - TestSuite

Answer : B

Explanation

TestCase contains a test case and defines the fixture to run multiple tests.

Q 20 - Which of the following class contains methods to collect the results of executing a test case?

A - Assert

B - TestCase

C - TestResult

D - TestSuite

Answer : C

Explanation

TestResult class contains methods to collect the results of executing a test case.

Q 21 - Which of the following class is a Composite of Tests?

A - Assert

B - TestCase

C - TestResult

D - TestSuite

Answer : D

Explanation

TestSuite class is a Composite of Tests.

Q 22 - Which of the following annotation tells JUnit that the public void method to which it is attached can be run as a test case?

A - @Test

B - @Before

C - @After

D - @BeforeClass

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 23 - Which of the following annotation causes that method to be run before each Test method?

A - @Test

B - @Before

C - @After

D - @BeforeClass

Answer : B

Explanation

Annotating a public void method with @Before causes that method to be run before each Test method.

Q 24 - Which of the following annotation causes that method to be run after each Test method?

A - @Test

B - @Before

C - @After

D - @AfterClass

Answer : C

Explanation

Annotating a public void method with @After causes that method to be run after each Test method.

Q 25 - Which of the following annotation causes that method run once before any of the test methods in the class?

A - @Test

B - @Before

C - @BeforeClass

D - @AfterClass

Answer : C

Explanation

Annotating a public static void method with @BeforeClass causes it to be run once before any of the test methods in the class.

Answer Sheet

Question Number Answer Key
1 A
2 B
3 C
4 C
5 C
6 C
7 D
8 C
9 C
10 D
11 C
12 A
13 D
14 C
15 C
16 C
17 A
18 A
19 B
20 C
21 D
22 A
23 B
24 C
25 C

junit_questions_answers.htm

Advertisements
E-Books Store