Important terms n n Blackbox testing Whitebox testing
Important terms n n Black-box testing White-box testing Regression testing Test coverage v 1. 6 08/02/2006 1
Debugging § § § v 1. 6 Debug Perspective Debug Session Breakpoint Debug Views Breakpoint Types Evaluating and Displaying Expressions 08/02/2006 2
Debugging » n Debugging in Eclipse The Java Debugger Part of Eclipse Java Development Tools (JDT) q More than System. out. printn( error ) q Detects errors as code executes q Correct errors as code executes q Actions you can perform debugging include: q Control Execution ; Set simple breakpoints ; Set conditional breakpoints ; Review and change variable values ; Hot code replace (feature new to JRE 1. 4) ; v 1. 6 08/02/2006 3
Debugging » Debug Perspective Threads and Monitor View Variable View Editor View Console View Outline View Tasks View v 1. 6 08/02/2006 4
Debugging » n Breakpoint q q n Simple Breakpoint Stops the execution of a program at the point Thread suspends at the location where the breakpoint is set Setting a breakpoint q q CTRL+Shift+B at current point in editor line Double click in editor’s marker bar at current line v 1. 6 08/02/2006 5
Debugging » n Select Java class containing the following: q q n n Starting a Debugging Session main() method Resulting execution will pass breakpoint Select Run » Debug As » Java Application Or Select Debug As » Java Application from the dropdown menu on the Debug tool bar. v 1. 6 08/02/2006 6
Debugging » n n Debug Session Execution suspends prior to the line with a breakpoint You can set multiple breakpoints v 1. 6 08/02/2006 7
Debugging » n Deleting Breakpoints Double click on the breakpoint in the editor v 1. 6 08/02/2006 8
Debugging » n Step Into or F 5: q q q n For methods, execute method and suspend on first statement in the method For assignments, similar to Step Over For conditionals, similar to Step Over or F 6 q n Control Execution From Breakpoint… Execute next statement Step Return or F 7 q Resume execution to the end of the method on the next line after it was invoked v 1. 6 08/02/2006 9
Debugging » n Resume or F 8 q n Control Execution From Breakpoint Continue execution until program ends or another breakpoint is reached Terminate q Stops the current execution thread v 1. 6 08/02/2006 10
Debugging » n Variables and Fields To see the values bound to fields: q q q Use Variables View Select variable in editor and select Inspect Select variable in editor and select Display v 1. 6 08/02/2006 11
Debugging » Code Debugging in this Module public class Debug { private int something = 0; private Vector list = new Vector(); public void first. Method(){ third. Method(something); something = something + 1; } public void second. Method(){ third. Method(something); something = something + 2; } public void third. Method(int value){ something = something + value; } public static void main(String[] args) { Debug debug = new Debug(); debug. first. Method(); debug. second. Method(); } } v 1. 6 08/02/2006 12
Debugging » n Variables View Shows all fields of instance where breakpoint occurred q q q Select this to see all fields Select any field to see value If field is bound to an object, you can select Inspect from the menu to view its fields and values v 1. 6 08/02/2006 13
Debugging » n Changing Field Values To change field value: Select field in Variables view q Select Change Variable Value from the menu q Enter new value into Set Variable Value window q Click OK q v 1. 6 08/02/2006 14
Debugging » n n Display View Displays the result of evaluating any expression in the current context Opens by: q q Selecting a field in the editor or Variables View and choosing Display Clicking on the Display tab v 1. 6 08/02/2006 15
Debugging » n n Remembers all objects you have inspected Displays the fields of the object q q n Expressions View You can see the values of the fields You can Inspect the fields Opens when: q q You Inspect an object You click on the Expressions tab v 1. 6 08/02/2006 16
Debugging » n n Lists all available breakpoints Can be used for manipulating breakpoints (through the views menu): q q q n n Breakpoint View Enabling Disabling Removing Also displays breakpoints properties Accessed like other debugging views v 1. 6 08/02/2006 17
Debugging » n Shows: q q q n Debug View Active threads Current stack frame when execution has stopped Previous stack frames Method and variables are shown in the editor for the selected frame q Update in the editor updates the source v 1. 6 08/02/2006 18
Debugging » n Breakpoint Types Breakpoints can be set for the following Java entities: Line (simple breakpoint) q Method q Field (watchpoint) q Java Exception q n Each breakpoint is set a different way and has different properties v 1. 6 08/02/2006 19
Debugging » n n Method Breakpoints To set method breakpoint: q Select method in the Outline View q From context menu select Toggle Method Breakpoint To set breakpoint’s properties: q Select breakpoint in editor. From the context menu, select Breakpoint Properties. . from the context menu q In the Properties dialog, Check Enabled to enable the breakpoint ; ; Check Hit Count to enable hit count. Breakpoint suspends execution of a thread the nth time it is hit, but never again, until it is re-enabled or the hit count is changed or disabled. Choose Enable condition to have breakpoint enabled only if the specified condition occurs. condition is 'true' option: Breakpoint stops if the condition evaluates to true. The expression provided must be a boolean expression. n value of condition changes option: Breakpoint stops if result of the condition changes. 08/02/2006 20 n v 1. 6
Debugging » n n Also known as watchpoint To set the watchpoint: q q n Select field in the Outline View From context menu select Toggle Watchpoint To set watchpoint’s properties: q q q Select breakpoint in editor Select Breakpoint Properties. . from context menu Set properties as desired ; n Field Breakpoints Access/modification, enable Execution suspended on access/modification of field v 1. 6 08/02/2006 21
Debugging » n Java Exception Breakpoint To Add Java Exception Point: q q q Select Run » Add Java Exception Point from main menu Enter exception type Specify what triggers a breakpoint: ; ; ; v 1. 6 Caught exception Uncaught exception Both 08/02/2006 22
Debugging » n How To Debug Here are simple steps for debugging in Eclipse: Set your breakpoints q Hit a breakpoint during execution q Walk/step through code to other breakpoints q Follow along in editor q Inspect/Display interesting fields q Watch the Console for things to happen q v 1. 6 08/02/2006 23
Debugging » n Summary You have learned: The views in the Debug Perspective q Typical debug session q How to use the Inspector q About the different types of breakpoints q How to set breakpoints q How step around your code doing debugging q v 1. 6 08/02/2006 24
- Slides: 24