Skip to content

JUnit Java Baselines

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

JUnit Java Baselines

All 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 feature introduced in Java 9 to 23 that would have changed how users write tests.

Will there be such a major feature in future?

No need to leave 8

Some interesting Java features were either backported to Java 8 or

  • JFR was backported
  • record behave as normal classes

Multi-Release JAR

JUnit 5 uses the multi-release JAR technique to support Java 9+ features:

  • Java Modules
  • Console API
  • Virtual Threads

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