Introduction

     

Testing and debugging code is a fact of life for Java developers, and this chapter focuses on the testing and debugging facilities that come with Eclipse. Often, you can test your code using the JUnit package that comes with Eclipse, and you can debug it using the built-in debugger. We'll look at both facilities in this chapter.

JUnit is an open source testing framework (for more information on the Open Source Initiative, visit http://www.opensource.org). You use it to test the results of JUnit-based classes that call methods in your code. An Eclipse plug-in facilitates the process of running JUnit tests. Using JUnit, you can create a standard set of tests and distribute them to everyone working on your code; if someone edits your code, all that person needs to do is to run the tests with a few mouse clicks to make sure he didn't break anything.

JUnit works by calling your code using a set of assertion methods that test the return values from your code. Here are the JUnit tests:


assertEquals(a, b)

Tests if a is equal to b ( a and b are primitive values or must have an equals method for comparison purposes)


assertFalse(a)

Tests if a is false, where a is a Boolean value


assertNotNull(a)

Tests if a is not null, where a is either an object or null


assertNotSame(a, b)

Tests if both a and b do not refer to the same object


assertNull(a)

Tests if a is null, where a is either an object or null


assertSame(a, b)

Tests if both a and b refer to the same object


assertTrue(a)

Tests if a is true, where a is a Boolean value

When you run a JUnit application using the JUnit plug-in in Eclipse, it opens its own view to give you immediate feedback on which tests have passed and which have failed.



Eclipse Cookbook
Inside XML (Inside (New Riders))
ISBN: 596007108
EAN: 2147483647
Year: 2006
Pages: 232
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net