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

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

Explanation

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

Q 5 - Which of the following method of TestCase class creates a default TestResult object?

A - TestResult getTestResult()

B - TestResult createResult()

C - TestResult getTestResultInstance()

D - TestResult testResult()

Answer : B

Explanation

TestResult createResult() method creates a default TestResult object.

Q 6 - Which of the following method of TestResult class gets the number of detected failures?

A - int error()

B - int errorCount()

C - int failureCount()

D - int failure()

Answer : C

Explanation

int failureCount() method gets the number of detected failures.

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 - Annotating a public void method with @AfterClass causes that method to be run after each Test method.

A - false

B - true

Answer : A

Explanation

@AfterClass will perform the method after all tests have finished. This can be used to perform clean-up activities.

Q 9 - Automated Test cases are executed by using automation tool so less tester are required in automation testing.

A - true

B - false

Answer : A

Explanation

Automated Test cases are executed by using automation tool so less tester are required in automation testing.

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