JUnit Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to JUnit Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

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.

Q 2 - 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 3 - 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.

Answer : A

Explanation

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

Q 5 - 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.

Answer : B

Explanation

void addTestSuite(Class<? extends TestCase> testClass) method adds the tests from the given class to the suite.

Q 7 - 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 8 - @Test annotation along with expected attribute can be used to test the code whether code throws desired exception or not.

A - true

B - false

Answer : A

Explanation

@Test annotation along with expected attribute can be used to test the code whether code throws desired exception or not.

Q 9 - JUnit provides Test runners for running tests.

A - true

B - false

Answer : A

Explanation

JUnit provides Test runners for running tests.

Q 10 - Fixture includes setUp() method which runs once when test class loads.

A - true

B - false

Answer : B

Explanation

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

junit_questions_answers.htm
Advertisements