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

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

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.

Q 3 - Which of the following annotation causes that method run once after all tests have finished?

A - @Test

B - @After

C - @BeforeClass

D - @AfterClass

Answer : D

Explanation

Annotating a public static void method with @AfterClass cause that method run after all tests have finished. This can be used to perform clean-up activities.

Answer : C

Explanation

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

Q 5 - Which of the following method of TestCase class sets up the fixture, for example, open a network connection?

A - void setTestName()

B - void setUp()

C - void setUpFixture()

D - void setTestCase()

Answer : B

Explanation

void setUp() method sets up the fixture.

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

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 - If a test class is annotated with @Ignore then none of its test methods will be executed.

A - false

B - true

Answer : B

Explanation

If a test class is annotated with @Ignore then none of its test methods will be executed.

Q 9 - Testing is the testing of single entity (class or method).

A - true

B - false

Answer : B

Explanation

Unit Testing is the testing of single entity (class or method). Testing is the process of checking the functionality of the application whether it is working as per requirements.

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