Skip to main content


developerWorks  >  Java technology  >

Jump into JUnit 4

Streamlined testing with Java 5 annotations

developerWorks

Level: Introductory

Andrew Glover (aglover@stelligent.com), President, Stelligent Incorporated

20 Feb 2007

Register now or sign in using your IBM ID and password.

JUnit 4 has dropped the strict naming conventions and inheritance hierarchies of old, in favor of the streamlined flexibility of Java™ 5 annotations. In this tutorial, a supplement to his popular series on code quality, testing fanatic Andrew Glover shows you how to leverage the new features enabled by annotations, including parametric tests, exception tests, and timed tests. He also introduces JUnit 4's flexible fixtures and shows you how to use annotations, rather than suites, to logically group tests before running them. The tutorial includes several sample tests run in Eclipse and instructions for running JUnit 4 tests in older, incompatible versions of Ant.

In this tutorial

Share this tutorial

digg Digg this story
del.icio.us Post to del.icio.us
Slashdot Slashdot it!

This tutorial guides you step-by-step through the fundamental concepts of JUnit 4, with emphasis on the new Java 5 annotations. At the conclusion of this one-hour tutorial, you will understand the major changes to JUnit 4, as well as being familiar with features such as exception testing, parametric testing, and the new flexible fixture model. You will know how to do the following:

  • Declare a test

  • Use annotations (rather than suites) to logically group tests prior to running them

  • Run tests in Eclipse 3.2 or Ant, as well as from the command line

Prerequisites

To get the most from this tutorial, you should be familiar with Java development in general. This tutorial also assumes that you understand the value of developer testing and are familiar with basic pattern matching. To follow the section on running JUnit 4 tests, you should be able to work with Eclipse 3.2 as an IDE and with Ant 1.6 or greater. You need not be familiar with previous versions of JUnit to follow the tutorial.


System requirements

To follow along and try out the code for this tutorial, you need a working installation of Sun's JDK 1.5.0_09 (or later) or the IBM developer kit for Java technology 1.5.0 SR3. For the sections on running JUnit 4 in Eclipse, you need a working installation of Eclipse 3.2 or later. For the section on Ant, you need version 1.6 or greater.

The recommended system configuration for this tutorial is as follows:

  • A system supporting either the Sun JDK 1.5.0_09 (or later) or the IBM developer kit for Java technology 1.5.0 SR3 with at least 500MB of main memory
  • At least 20MB of disk space to install the software components and examples covered

The instructions in the tutorial are based on a Microsoft Windows operating system. All the tools covered in the tutorial also work on Linux and UNIX systems.



Duration

1 hour


Formats

html, pdf


Share this....

digg Digg this story del.icio.us del.icio.us Slashdot Slashdot it!


Back to top


Document options

Document options requiring JavaScript are not displayed

Discuss