Debugging: A necessary part of Software Development

Why use a debugger? To help fix errors. Eclipse has a "source level" debugger that allows us to

· Step through your own Java code one statement at a time

· Pause a running program at any point (set a "breakpoint" and start debugging session)

· Examine the content of variables (all available are show in the Variables view)

Three steps to debugging:


1) Realize you have an error

· Good test cases and JUnit assertions can expose bugs


2) Locate the source of an error--finding the method is a good start

· Set a breakpoint to run all tests to near the failing assertion.

· Breakpoint could be at the assertion, or

· To a previous message that may have caused the error


3) Fix the error

· Step into the method (F5)

· Step through the code (F5, or F6 to step over other methods)

· Observe variables as they change and the flow of statements

· Simply walking through code step by step can help you see things that were not otherwise apparent.

Eclipse Debugging Commands

· Set a breakpoint so you can run code up to that statement

o double click to the left of the statement, or

o Right click > Select Toggle Breakpoint

· In a JUnit test:

o Run > Debug As > JUnit test, or

o Right click on the file with executable code and chose Debug As > JUnit test, or

o Click the Debug icon to run the most recently run debugging session again

· Step to to the next statement, even if it has a method call

o F5, or

o Run > Step into, or

o Click the Step into icon

· Evaluate an Expression

o Right click expression > Display

Setting Step filters (Non Macs, start with Window)

· Select Preferences > Java > Debug > Step Filtering and click Use Step Filters

· Click Add Packages , enter junit, select choices press OK

· Click Select all

With JUnit, terminate the session by clicking the red box (or terminate in Debug view of the Debug perspective (see below)

The Debug Perspective with many views

Step into Step over Toggle Step Filters Toggle Breakpoints & current debug pointer