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

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.

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

Answer : C

Explanation

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

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

Q 6 - 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 7 - 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 8 - @Test annotation along with timeout attribute can be used to set timeout of a test case.

A - false

B - true

Answer : B

Explanation

@Test annotation along with timeout attribute can be used to set timeout of a test case.

Q 9 - Parameterized tests allow developer to run the same test over and over again using same values.

A - true

B - false

Answer : B

Explanation

Parameterized tests allow developer to run the same test over and over again using different values.

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

A - true

B - false

Answer : A

Explanation

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

junit_questions_answers.htm
Advertisements