Book Image

Instant Eclipse Application Testing How-to

By : Anatoly Spektor
Book Image

Instant Eclipse Application Testing How-to

By: Anatoly Spektor

Overview of this book

<p>Detecting bugs and flaws in an application is difficult. Eclipse is a multi-language software development environment comprising of an Integrated Development Environment (IDE) and an extensible plugin system. Testing the Eclipse Platform during every build using an extensive suite of automated tests helps in disclosing bugs and rectifying them.<br /><br />"Instant Eclipse Application Testing How-to" is a quick guide to learning how to test all types of Java applications in an Eclipse environment. This book gives you a step-by-step approach towards application testing and debugging along with optimized sample test projects.<br /><br />"Instant Eclipse Application Testing How-to" is a hands-on guide that gives developers an insight into how to test Java applications using Eclipse IDE. This book will guide you through the process by allowing you to create a Java application and debug it using a wide variety of Eclipse debugging tools. The book is filled with practical examples, so you will start coding and debugging right away. After reading the book you will be proficient enough to debug Java applications of any scope.</p>
Table of Contents (7 chapters)

Using Watchpoint (Intermediate)


Watchpoint is a very useful tool that is used to track access and/or modification of the variables. The Watchpoint is a type of breakpoint that stops whenever a variable is either accessed, modified, or both.

Getting ready

Please make sure that you don't have any breakpoints checked in the Breakpoints view list and the debugger is terminated.

How to do it...

  1. Go to the Outline view and find the number variable.

  2. Right-click on number and select Toggle Watchpoint. See the following screenshot:

    If you go to line 9, you will see that there is a Watchpoint icon instead of a breakpoint. This means that the current variable is being watched. Also, if you want to unset Watchpoint, just double-click on the icon. If you want to set it back, double-click again.

  3. Run the debugger.

    The first time when Watchpoint is triggered, the application stops at line 47; that is because the main() method at line 110 called the setNumber() method that assigned a number to the value set by the user.

  4. Click on the Resume icon.

    This time the application stops at line 90; that is because the toString() method requested access to the number variable. Note that number was modified the previous time, but this time number was accessed without modification.

  5. Terminate the debugger.

Now let's assume that we are not interested in watching the access of the variable, we just want to know where it is modified.

  1. Go to line 9, right-click on the icon, and select Breakpoint Properties….

  2. Uncheck Access and click on Ok.

    Now your breakpoint icon looks like this: , which means that Watchpoint will be triggered only when a variable is modified.

  3. Run the debugger.

    Once again the application stopped at line 47 because we are modifying the variable.

  4. Click on the Resume icon.

Now we can see the difference between this execution and the previous one. This time without stopping on line 90, the application just finished execution and terminated. This is because we are not tracking access of the variable, just its modification. The Watchpoint is a very useful tool if you want to track how your variable changes and when it gets accessed, but sometimes you want to simply run the application and just see the output in the console. For this purpose, you should use a conditional breakpoint and print its output to the user or simply use a breakpoint type called Printpoint.