Skip to content

JUnit Java Baselines

Christian Stein edited this page Oct 29, 2024 · 5 revisions

JUnit Java Baselines

JUnit 5 is developed using a trunk-based model: new features and bug fixes are happening at https://github.com/junit-team/junit5/commits/main/ (the tip) with only critical fixes are backported to older 5.x branches (tails).

All major JUnit releases are usable on the latest-and-greatest (read: tip) Java release, which is JDK 23.0.1 as of today. This is due to JUnit's authors strived to use only supported API of Java when implementing features. Combined with Java's excellent backward and forward compatibility users of JUnit seldom care about JUnit's Java base line version. For example, test code compiled with Java 5 and using JUnit 3 API can still be run on Java 24 Early Access without changing a thing.

So, when did the Java base line for JUnit change?

  • JUnit 0 - 1997 - Java 1 - extends TestCase - Test method names must begin with test.
  • JUnit 3 - 2002 - Java ? - Merged with JUnit 4 by now.
  • JUnit 4 - 2006 - Java 5 - @Test - Test methods are annotated with @Test.
  • JUnit 5 - 2017 - Java 8 - () -> {} - Dynamic tests using Lambdas.

What's the main driver to upgrade JUnit to require a new Java base version?

A Java feature that impacts how users write tests:

There was no standalone/major feature introduced in Java 9 to 23 that would have changed how users write tests.

Will there be such a major feature in future?

Will there be an amount of accumulated "minor" features that would users want to use?

No need to leave 8

Some interesting Java features were either backported to Java 8 by OpenJDK or they blend-in naturally.

  • JFR was backported
  • record behave as normal classes

For a small subset of features JUnit 5 uses the multi-release JAR technique to support Java 9+ features:

  • Java Modules - Java 9 - 1st class module-info support, --select-module, and --scan-modules
  • Console API - Java 17 - default charset retrieval
  • Virtual Threads - Java 21 - WIP

JUnit 5 is built with JDK 21 using javac's --release 8 option. Self-tests can be written using Java 21 API.

JUnit as a Platform

Test authors are a the largest consumer group of JUnit API. Tool authors are another important group of JUnit's costumers.

Stability is key.

Clone this wiki locally