Why Not Just Use a Debugger for Unit Testing?

Submitted by: Administrator
This is a common question in a job interview. You should answer it with these points:

* A debugger is designed for manual debugging and manual unit testing, not for automated unit testing.
* JUnit is designed for automated unit testing.
* Automated unit testing requires extra time to setup initially. But it will save your time, if your code requires changes many times in the future.

Here is how the JUnit FAQ answers this question:

Debuggers are commonly used to step through code and inspect that the variables along the way contain the expected values. But stepping through a program in a debugger is a manual process that requires tedious visual inspections. In essence, the debugging session is nothing more than a manual check of expected vs. actual results. Moreover, every time the program changes we must manually step back through the program in the debugger to ensure that nothing broke.

It generally takes less time 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 expected values, the tests may be telling you that shorter and more cohesive methods would improve your design.
Submitted by: Administrator

Read Online JUnit Job Interview Questions And Answers