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 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 : A

Explanation

Test runner is used for executing the test cases.

Q 3 - 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 : B

Explanation

void assertTrue(boolean condition) checks that a condition is true.

Answer : B

Explanation

void addFailure(Test test, AssertionFailedError t) method adds a failure to the list of failures.

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 @After causes that method to be run after each Test method.

A - false

B - true

Answer : B

Explanation

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

Q 8 - Which of the following class is used to run test cases?

A - JUnitCore

B - TestCase

C - TestSuite

D - TestResult

Answer : A

Explanation

The test cases are executed using JUnitCore class.

Q 9 - JUnit 4.0 provides Annotations to identify the test methods.

A - true

B - false

Answer : A

Explanation

JUnit 4.0 provides Annotations to identify the test methods.

Q 10 - Unit Tests are written after the code during development in order to help coders test the code.

A - true

B - false

Answer : B

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