In this section, you will debug a Java program.
1. |
In the Package Explorer view in the Java perspective, double-click junit.samples.VectorTest.java to open it in an editor. |
2. |
Place your cursor on the marker bar (along the left edge of the editor area) on the following line in the setUp() method: fFull.addElement (new Integer(1)); and double-click to set a breakpoint. ![]() Note: The breakpoint is blue with no checkmark overlay as the breakpoint is not yet installed, meaning that the containing class has not yet been loaded by the Java VM. |
3. |
In the Package Explorer view, select the junit.samples package and select the Run menu. Within the Run menu, select Debug As, and then Java Application. |
4. |
Select the VectorTest - junit.samples - /JUnit item in the dialog, then click Finish. ![]() |
5. |
As soon as the breakpoint is hit, the Debug perspective opens, and execution is suspended. Notice that the process is still active (not terminated) in the Debug view. Other threads might still be running. ![]() Note: The breakpoint has an overlay icon of a checkmark because it is now installed (VectorTest has been loaded in the Java VM). |
6. |
In the editor in the Debug perspective, select the entire line where the breakpoint is set, and from its context menu, select Inspect. ![]() |
7. |
The expression is evaluated in the context of the current stack frame, and the results are displayed in the Expressions view. Select the expression in the Expressions view, and from its context menu, select Remove. |
8. |
The Variables view displays the values of the variables in the selected stack frame. Expand the fFull tree in the Variables view until you can see elementCount. ![]() |
9. |
Watch the variables (e.g., elementCount) in the Variables view as you step through VectorTest in the Debug view: Click the Step Over button to step over the highlighted line of code. Execution will continue at the next line in the same method (or, if you are at the end of a method, it will continue in the method from which the current method was called). Note: The variables that are changed as a result of the last step are highlighted in the color specified in the Debug Variable Views "Changed Variable Value Color" preference (the default color is red).![]() |
10. |
If the program has not executed fully when you are done debugging, select Terminate from the context menu of the program's launch item in the Debug view. |