In this lab, you will explore the Debugger in Eclipse. If you already use the Eclipse debugger, this lab may provide you with more information. If you are new to Eclipse, make sure to watch the video in the Resources section below to get oriented to the vocabulary and basic function of the debugger.
Video: Norm Krumpe’s Debugger Tutorial (~15 min) covers basic vocabulary and explains how to track variables in different areas in the Eclipse screen, the difference between step-in and step-out, etc.
Beginner’s Guide to Quick Start Debugging is a written reference with screenshots that explains how to get started and can serve as reminders of how things work as you debug.
Estimator.exp has the expected output of the Estimator for reference.
Never click “Step” before thinking about what you expect to happen.
The debugger won’t magically tell you when something has gone wrong in your code. It only allows you to observe what happens one step at a time. If you don’t have an expectation for what should happen, you will have no way of noticing when something goes wrong.
Never “Step-Into” a method unless you have already determined that it contains a defect.
There is no need to waste time stepping through the instructions of a method that is working correctly. When you reach a method call, the default should be to “Step Over”. If the outcome is unexpected, you’ve learned there is a problem: now you can restart debugging and “Step Into” the method to figure out what’s wrong.
Be prepared to rewrite code to be debugger-friendly.
Imagine we step over the following statement and something goes wrong:
Now we are in an awkward situation. We know there is a problem on this line, but we don’t have a good way of narrowing it down. The debugger will be more useful if we rewrite the code as follows:
BookID miceID;
Book miceBook;
miceID = catalog.lookup("Of Mice and Men");
miceBook = library.removeBook(miceID);
bookshelf.addBook(miceBook);
This is more verbose, but it allows us to narrow down the source of the problem by stepping over one method call at a time.
If you haven’t already, update your Eclipse settings to prevent stepping into imported libraries:
org.junit.*