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 method breakpoint (Intermediate)


This breakpoint is very useful when you are dealing with large methods, or if you are concerned about what values enter the method and what values exit from the method.

Getting ready

Before we start, I want you to remove line 113, which throws NullPointerException (used in the previous example) and change line 112 to its normal state:

andrew.setPosition("tester");

How to do it...

  1. Go to the setAge(int) method definition (on line 60) and set a breakpoint as you usually do it.

    Your breakpoint icon should look like this . As you see, this icon is different from the regular breakpoint icon that you have seen before. This is because you have set a method breakpoint.

  2. Run the debugger.

    The application has stopped at the first line after the setAge() method definition (on line 61). The breakpoint has been triggered because the method was called by the main() method (as shown on line 111; you can see all this in the Debug view). So every time this method is called, your application will break at the start of the method. This allows you to see what values were passed to the method. This is very useful, but what I find even more useful is setting the breakpoint when the application leaves the method. This will allow you to see how values have changed when the method finished running. Let's try it right now.

  3. Terminate the debugger, go to line 60, and open Breakpoint Properties….

  4. In Breakpoint Properties…, uncheck Method Entry and check Method Exit and click on Ok.

    If you did this correctly, you will see that the breakpoint icon has changed again. Now it looks like this: . The arrow in the breakpoint icon shows when the breakpoint should be triggered, at the start or at the end of the method.

  5. Run the debugger.

If you remember, when we ran the debugger for the first time in this example, it stopped at line 61, but now it stopped right before leaving the method (on line 64). Also, if the method has a return statement, the debugger will break right before the return. Use a method breakpoint when you know for sure that the issue you are facing is caused by the particular method, or when you want to see how many times a method was called, in what circumstances, and what values it received and/or returned. Moreover, if both entry and exit breakpoints are set, we can easily follow what variables have been changed by looking at the Variables view.