Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Catching up with JUnit

Catching up with JUnit

It’s an unusual year for JUnit. The testing framework will see not one but three feature releases in 2025. Version 5.12 was released in February, 5.13 will be released in May, and 6.0 is scheduled for September.

First, we’ll look at JUnit 5.12, which introduced support for the new version of the Open Test Reporting XML format, including output capturing, file attachments, and a new HTML report. Contrary to the legacy XML format, Open Test Reporting supports all features of the JUnit Platform. Moreover, adoption by other ecosystems has already started.

Next, we’ll cover JUnit 5.13, which added support for parameterizing test classes rather than just methods. Parameterized classes were the most highly voted issue in JUnit’s issue tracker. Besides unlocking new use cases, they finally offer a straightforward migration path from JUnit 4 parameterized tests.

Last but not least, we’ll share our plans for JUnit 6.0 which, among other things, will raise the Java and Kotlin baselines to 17 and 2.x, respectively.

Avatar for Marc Philipp

Marc Philipp

June 04, 2025
Tweet

More Decks by Marc Philipp

Other Decks in Programming

Transcript

  1. Open Test Reporting XML format • • junit-platform- reporting •

    junit.platform.reporting.open.xml.enabled=true 11
  2. Event-based format <?xml version="1.0" ?> <e:events xmlns="https:��schemas.opentest4j.org/reporting/core/0.1.0" xmlns:e="https:��schemas.opentest4j.o <infrastructure><hostName>�����hostName><userName>marc��userName><operatingSystem>Mac OS

    X��operatingSystem <e:started id="766" name="JUnit Jupiter" time="2022-09-23T07:54:50.324086Z"><metadata><junit:uniqueId <e:started id="767" name="ColorPaletteTests" parentId="766" time="2022-09-23T07:54:50.324275Z"><metadata <e:started id="768" name="DemonstratePalettesTests" parentId="767" time="2022-09-23T07:54:50.324456Z" <e:started id="769" name="flat_default()" parentId="768" time="2022-09-23T07:54:50.324589Z"><metadata <e:finished id="769" time="2022-09-23T07:54:50.326039Z"><result status="SUCCESSFUL">��result>��e:finished <e:finished id="768" time="2022-09-23T07:54:50.332254Z"><result status="SUCCESSFUL">��result>��e:finished <e:finished id="767" time="2022-09-23T07:54:50.333862Z"><result status="SUCCESSFUL">��result>��e:finished <e:finished id="766" time="2022-09-23T07:54:50.812066Z"><result status="SUCCESSFUL">��result>��e:finished ��e:events> 12
  3. Hierarchical format <?xml version="1.0" encoding="UTF-8" standalone="no"?> <h:execution xmlns:h="https:��schemas.opentest4j.org/reporting/hierarchy/0.1.0" xmlns="https:��schemas.open <infrastructure>����

    ��� �����infrastructure> <h:root duration="PT0.48798S" name="JUnit Jupiter" start="2022-09-23T07:54:50.324086Z"> <metadata> <junit:uniqueId>[engine:junit-jupiter]��junit:uniqueId> <junit:legacyReportingName>JUnit Jupiter��junit:legacyReportingName> <junit:type>CONTAINER��junit:type> ��metadata> <result status="SUCCESSFUL"�� <h:child duration="PT0.009587S" name="ColorPaletteTests" start="2022-09-23T07:54:50.324275Z"> <metadata>���� ��� �����metadata> <sources><java:classSource className="org.junit.platform.console.tasks.ColorPaletteTests"���� <result status="SUCCESSFUL"�� <h:child duration="PT0.007798S" name="DemonstratePalettesTests" start="2022-09-23T07:54:50.324456Z" <metadata>���� ��� �����metadata> <sources><java:classSource className="org.junit.platform.console.tasks.ColorPaletteTests$Demonstrat <result status="SUCCESSFUL"�� <h:child duration="PT0.00145S" name="flat_default()" start="2022-09-23T07:54:50.324589Z"> <metadata>���� ��� �����metadata> <sources><java:methodSource className="org.junit.platform.console.tasks.ColorPaletteTests$Demonst <result status="SUCCESSFUL"�� ��h:child> ��h:child> 13
  4. Parameterized Test Methods • @ParameterizedTest • @���Source class SomeTests {

    @ParameterizedTest @ValueSource(strings = {"foo", "bar"}) void shouldNotBeNull(String value) { assertNotNull(value); } @ParameterizedTest @ValueSource(strings = {"foo", "bar"}) void lengthShouldBeThree() { assertEquals(3, value.length()); } } 19
  5. Parameterized Test Classes • @ParameterizedClass • @���Source @ParameterizedClass @ValueSource(strings =

    { "foo", "bar"}) class SomeTests { @Parameter String value; @Test void shouldNotBeNull() { assertNotNull(value); } @Test void lengthShouldBeThree() { assertEquals(3, value.length()); } } 20
  6. Consuming Arguments • • @ParameterizedClass @ValueSource(strings = { "foo", "bar"})

    record SomeTests(String value) { @Test void shouldNotBeNull() { assertNotNull(value); } @Test void lengthShouldBeThree() { assertEquals(3, value.length()); } } 21
  7. Argument Source Annotations • @ValueSource @EnumSource @NullSource @EmptySource • @CsvSource

    @CsvFileSource • @MethodSource @FieldSource • @ArgumentsSource(MyProvider.class) 24
  8. Valid test methods? @Test �� Java int test() { return

    42; } @Test �� Kotlin fun test(): Nothing = fail() 28
  9. Valid test methods? @Test �� Java int test() { return

    42; } @Test �� Kotlin fun test(): Nothing = fail() @Test void Unit 28.1