Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

JUnit Interview Questions and Answers

Ques 11. Why Not Just Use System.out.println() for Unit Testing?

If we add debug statements into code, it is a low-tech method for debugging it. It usually requires that output be scanned manually every time the program is run to ensure that the code is doing what's expected.

It generally takes less time in the long run to codify expectations in the form of an automated JUnit test that retains its value over time. If it's difficult to write a test to assert expectations, the tests may be telling you that shorter and more cohesive methods would improve your design.

Is it helpful? Add Comment View Comments
 

Ques 12. Under What Conditions Should You Test set() and get() Methods?

We should test to target areas that might break. set() and get() methods on simple data types are unlikely to break. So no need to test them.

set() and get() methods on complex data types are likely to break. So you should test them.

Is it helpful? Add Comment View Comments
 

Ques 13. Do You Need to Write a Test Class for Every Class That Need to Be Tested?

This is an interesting question.

The technical answer is no. There is no need to write one test class for each every class that need to be tested. One test class can contain many tests for many test target classes.

But the practical answer is yes. You should design one test class per test target class for low level basic tests. This makes your test classes much easier to manage and maintain. You should write separate test classes for high level tests that requires multiple target classes working together.

Is it helpful? Add Comment View Comments
 

Ques 14. Can You Explain the Life Cycle of a JUnit3.8 Test Case Class?

Test case class contains a setUp() method, a tearDown() method and multiple testXXX() methods. When calling a test runner to run this test class, the runner will execute those methods in a specific order giving the test case class an execution life cycle like this:

setUp()

testXXX1()

tearDown()

setUp()

testXXX2()

tearDown()

Is it helpful? Add Comment View Comments
 

Ques 15. Please Explain the Life Cycle of a JUnit 4.4 Test Class?

A JUnit 4.4 test class contains a @Before method, an @After method and multiple @test methods. When calling a test runner to run this test class, the runner will execute those methods in a specific order giving the test class an execution life cycle like this:

@Before
@Test XXX1
@After

@Before
@Test XXX2
@After

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook