In this section, you will debug a Java program.
1. |
In the Packages 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. ![]() Adding a Breakpoint Note: The breakpoint is blue because it is unverified, meaning that the containing class has not yet been loaded by the Java VM. |
3. |
In the Packages view, select the junit.samples package and click the Debug button in the toolbar. |
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 Processes view. Other threads might still be running. ![]() Note: The breakpoint is green because is it now verified. |
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 Inspector view. Select the expression in the Inspector 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 do the following in the Debug view to step through VectorTest: 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). ![]() |
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 either the Processes view or the Debug view. |