Chapter 1. Fundamentals

 

This chapter covers

  • An introduction to Programmer Testing
  • Getting started with JUnit
  • A few good practices for JUnit
  • Why testing replaces debugging

We hate debugging.

You look up at the clock to see how late it is because you still have a handful of defects that need to be fixed tonight. Welcome to the “fix” phase of “code and fix,” which is now entering its third month. In that time, you have begun to forget what your home looks like. The four walls of your office—assuming you even have four walls to look at—are more familiar than you ever wanted them to be. You look at the “hot defects” list and see one problem that keeps coming back. You thought you fixed that last week! These testers...when will they leave you alone?!

Fire up the debugger, start the application server—grab a coffee because you have five minutes to kill—set a breakpoint or two, enter data in 10 text fields and then press the Go button. As the debugger halts at your first breakpoint, your goal is to figure out which object insists on sending you bad data. As you step through the code, an involuntary muscle spasm—no doubt from lack of sleep—causes you to accidentally step over the line of code that you think causes the problem. Now you have to stop the application server, fire up the debugger again, start the application server again, then grab a stale doughnut to go with your bitter coffee. (It was fresh six hours ago.) Is this really as good as it gets?

1.1. What is Programmer Testing?

1.2. Getting started with JUnit

1.3. A few good practices

1.4. Summary