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.
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 jens-uwe.pipka@jup-net.de.
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.
Check that Java 5.0 is used.
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.
Change import Statement: Replace import junit.framework.TestCase; with import org.junit.*; import junit.framework.JUnit4TestAdapter;
Introduce Annotations:
Insert @Test in front of any test..() method, i.e. so called test fixture.
Insert @Before in front of the original setUp() method
Insert @After in front of the original tearDown() method
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(...)
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);
}
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.
Check that Java 5.0 is used.
Insert junit.jar from JUnit 4.x in your class path.
Do not extend the new class from junit.framework.TestCase
Import the JUnit 4.x
relevant classes:
import
org.junit.*;
import junit.framework.JUnit4TestAdapter;
Annotate new test methods with @Test
Annotate the test fixture with @Before and @After for specific initialization.
Use Assert.assertEquals(...) to check the actual results with the expected ones.
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);
}
One time setup: Use @BeforeClass and @AfterClass to initialize specific resources that should be initialized only once during the run of a certain test case.
Exception handling: You can set a parameter for the @Test Annotation which exceptions should be thrown: @Test(expected=<classname>.class)
Ignoring a Test: You can ignore an test by using the @Ignore annotation.
This compact overview is also available as Download: JUnit40QuickStartGuide.pdf
Jens Uwe Pipka
E-Mail: jens-uwe.pipka@jup-net.de