8.08.2011

JUnit - An Introduction

JUnit is a testing framework written by Erich Gamma (one of the Gang of Four) and Kent Beck (creator of Extreme Programming and TDD). Integrating the JUnit framework into your project allows you to quickly develop unit tests without worrying about implementation details of the framework itself.

The JUnit team has the following design goals for the framework (From A Cook's Tour):

  • Aid in the creation of useful test
  • The tests must retain their value over time
  • Test reuse should reduce the cost of writing tests

Setting up JUnit is easy. Download the distribution and add the JUnit jar to your classpath.

Classes no longer need to extend TestCase (as in JUnit 3) in JUnit 4. Test methods are indicated with the @Test annotation. Before and After methods are annotated with the @Before and @After annotations respectively.