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 a hit count breakpoint (Intermediate)


Sometimes you want your breakpoint to be triggered when the line is triggered n times. For example, you have a loop and you are interested in inspecting your application only when the counter hits 50, then you use the Hit Count option of the breakpoint. Also sometimes, as I have already mentioned, one line can be called hundreds of times, and if you want to explore a particular situation, you just set your Hit Count to the number at which the breakpoint should be triggered. Thus, the debugger will skip the breakpoint n times and trigger on the count you specified.

Getting ready

Please terminate the debugger if it is still running, remove Printpoint that we have set up in the previous example, and uncomment line 113.

How to do it...

  1. After line 112, please add two more lines:

    andrew.setPosition("programmer");
    andrew.setPosition("employee");

    We need it so that we can call one function several times.

  2. Go to line 31 (if statement of setPosition()) and set a breakpoint.

  3. Right-click on this breakpoint and select Breakpoint Properties….

  4. Check the Hit count option and enter 3 as shown in the following screenshot:

  5. Click on Ok and run the debugger.

    If you did everything correctly, your program should stop at line 31. Take a look at the Debug view. Your stack shows that setPosition() was called by the main() method on line 114. Line 114 is the third occurrence of the setPosition() function, which means that the two previous occurrences were skipped.

  6. Click on the Resume icon.

Imagine if we do not put the Hit Count breakpoint, then the breakpoint would be triggered for the second and third time. But because we have set Hit count to 3, the breakpoint was triggered only on the third occurrence and simply finished execution.

Now you know how the Hit Count breakpoint works. Please delete lines 113 and 114 that we have added specifically for this example. Also unset the Hit Count breakpoint and terminate the debugger before we move to the next recipe.