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


An exception breakpoint is triggered when an exception gets caught and/or uncaught. When you have a big project, sometimes it is very annoying to go through the whole exception stack trace trying to figure out what line caused an exception to be thrown. With an exception breakpoint, you can specify what exception you want to set on the breakpoint, and whenever this particular exception is about to be thrown, the application will stop at the line that caused the exception.

Getting ready

Let's revert the changes we made in the previous steps.

Uncomment the if statement in setPosition(String) (on line 31 and 33), unset the conditional breakpoint (double-click on the breakpoint to unset it), and terminate the debugger.

We will modify line 112 again, but this time we will pass null as an argument. So your line 112 should look like the following line of code:

andrew.setPosition(null);

We will also add one extra line after line 112. Type andrew.getPosition().length().

In this line we have intentionally created NullPointerException, as we are trying to find the length of a string, which is equal to null. This is done to show how exception breakpoint works.

How to do it...

  1. Go to the Debug Perspective, then to the Breakpoints view, and click on the icon. (Add Java Exceptions.)

    We will be dealing with NullPointerException. Thus, you need to find it in the list. See the following screenshot:

  2. Click on Ok. Now you should see the NullPointerException breakpoint added in the breakpoint list. If there is any other breakpoint checked, please uncheck it.

  3. Run the debugger.

    If you did everything correctly, you should see that the application stopped at line 113, right before throwing an exception.

  4. Click on the Resume icon.

After the application has finished executing, you should see an exception stack in your console as shown in the following screenshot:

As you can see, the Eclipse debugger has stopped right before an exception has been thrown, thus allowing you to look around and possibly find a reason for the exception. This makes the exception breakpoint very useful when dealing with debugging applications that throw unexpected exceptions.