JUnit Online Quiz


Advertisements

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

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

Q 6 - 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 7 - 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 8 - @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.

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 before every test invocation.

A - true

B - false

Answer : A

Explanation

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

junit_questions_answers.htm

Useful Video Courses


Video

JUnit Online Training

24 Lectures 2.5 hours

Nishita Bhatt

Video

A Practical Guide to JUnit 5

56 Lectures 7.5 hours

Dinesh Varyani

Advertisements