Java News from Thursday, January 19, 2006

Kent Beck and David Saff have posted the second release candidate of JUnit 4, though I'd classify this as amore of an alpha (i.e. feature list and API still subject to change) than a real release candidate. According to Saff,

The first and most important point is this: early adopters, 99% of your JUnit 4 test cases still work, and now work better than before!

Back in October, Kent said "The remaining functionality we need to add is a way to specify test suites that is represented in source code and works with automated refactoring tools. Once that is in place we will javadoc everything, package it, and deploy." We thought about it, and realized that what this really meant was

  1. JUnit's extension mechanism should be so powerful that test suites can be just another extension.
  2. Extensions should work seamlessly with IDE test runners, meaning
    1. Since IDE's and UI's like to display the names of tests before they're run, and match up successes and failures with these names, there must be a standard way to display the components of an extended test suite.
    2. There should be a standard way to run just a single method from a test class, with extension-defined setup and teardown behavior
    3. JUnit 4 should respond gracefully to user cancellation requests that come in the middle of a run
  3. Extensions should work seamlessly with JUnit 3 test runners
  4. There should be a simple API for running test classes, sets of test classes, single test methods, and any other test specification.

To support these goals, we needed the following concepts:

There is an important distinction between Requests and Plans. A Request might be "Please run all tests in class ValidationTest", with the corresponding Plan being "I will run methods foo, bar, baz, and foobar in class ValidationTest".

Again, nothing has changed about the basic annotation-based test definition API, so your existing test cases still work. A revised overview of the packages and classes as they stand now, and how to run a JUnit 4 test using a JUnit 3 runner, is at

http://people.csail.mit.edu/saff/junit4.0rc2api.txt

We believe that this robust extensibility, explicit IDE support, backward compatibility, and simple API are worth the extra time you've waited. We're very interested in feedback. To try things out, you can download the code from CVS, or, for a limited time only, download a list-members-only distribution from

http://people.csail.mit.edu/saff/junit4.0rc2.zip

We're especially interested in:

  1. Results of running JUnit 4 tests with various JUnit 3 runners.
  2. Experiences using JUnit 4 to write tests.
  3. New Runners and Requests.

Remember that this is not the final release--the implementation and API may still change as we respond to your comments and shake loose the remaining issues. Thanks,

Java 5 is required.