djux JUnit Extensions

The djux JUnitExtensions make it possible to define test resources as known from the Smalltalk SUnit. Unit tests are speeded up by using test resources, because time-consuming initializations are only done once and remain active over a series of tests. As an example, a database connection is opened before executing the first unit test and can be accessed during the whole testing circle. It isn't necessary to re-open the database connection before an unit test is executed.

Release Notes

With the djux JUnit Extensions, you can define TestResources and Extensible Test Cases (XTCs), including wrapper classes suitable for external programs. Furthermore, an enhanced SwingUI Testrunner with a graphical TestResources Browser is provided. Last but not least, you can write additional database tests with a simple and easy to use DatabaseChecker. The latest stable djux version is 1.52. It supports JUnit 3.x and as well as all JDKs until JDK 1.4.x.

Compatibility with Java 5 or higher is introduced with djux 1.60. A stable alpha version is already available that comes with the same functionality as known from djux 1.52. In parallel, we are also migrating djux with this version towards JUnit 4.x.

For any further questions, feedback or changes concerning djux do not hesitate to contact Jens Uwe Pipka at


A Quick Start Guide to JUnit 4.x

Migrating existing JUnit 3.x unit tests to as well as writing new unit tests with JUnit 4.0 or higher is much easier at it seems. Most important, only the JUnit framework that is used for test implementation has been changed; you can still execute the unit tests in your used test runner including the integrated Eclipse test runner or the JUnit 3.0 Swing test runner. As JUnit 4.x now comes with annotations, it is required to use Java 5.0 or above. In the following, we describe the necessary steps to get warm with JUnit 4.x for both, migrating existing unit tests as well as writing new ones.

Migrating existing Unit Tests

  1. Check that Java 5.0 is used.

  2. Within class path, replace junit.jar from Junit 3.x with the updated junit.jar from Junit 4.x. Your old unit test should still work with the new JUnit version.

  3. Change import Statement: Replace import junit.framework.TestCase; with import org.junit.*; import junit.framework.JUnit4TestAdapter;

  4. Introduce Annotations:

    1. Insert @Test in front of any test..() method, i.e. so called test fixture.

    2. Insert @Before in front of the original setUp() method

    3. Insert @After in front of the original tearDown() method

  5. The test case should not inherit from Test Case any more, thus delete extends TestCase. As a consequence, this.assertEquals is not accessible any longer. Therefore, replace this.assertEquals(...) with Assert.assertEquals(...)

  6. To execute an unit test based on Junit 4.x with an existing test runner, add the following method:
    public static junit.framework.Test suite() {
      return new Junit4TestAdapter(<classname>.class);

  7. That's all! Now, you can execute this unit test by calling SimpleUnitTest within your favourite test runner, including the Eclipse built-in test runner.

Writing new unit tests

  1. Check that Java 5.0 is used.

  2. Insert junit.jar from JUnit 4.x in your class path.

  3. Do not extend the new class from junit.framework.TestCase

  4. Import the JUnit 4.x relevant classes:
    import org.junit.*;
    import junit.framework.JUnit4TestAdapter;

  5. Annotate new test methods with @Test

  6. Annotate the test fixture with @Before and @After for specific initialization.

  7. Use Assert.assertEquals(...) to check the actual results with the expected ones.

  8. Insert the following method to run the unit test with an existing test runner:
    public static junit.framework.Test suite() {
      return new Junit4TestAdapter(<classname>.class);

Some Advanced Features:


This compact overview is also available as Download: JUnit40QuickStartGuide.pdf


Jens Uwe Pipka