Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

JUnit 6

JUnit 6

Thanks to the Sovereign Tech Fund I had the opportunity to work full-time on JUnit this year. In this talk, I‘ll report on my experiences and walk you through the new features and enhancements. Most prominently, those are Open Test Reporting, Parameterized Test Classes, Discovery Issues, and the new Java 17 and Kotlin 2.1 baselines.

Avatar for Marc Philipp

Marc Philipp

November 26, 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 12
  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> 13
  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> 14
  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()); } } 22
  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()); } } 23
  6. Consuming Arguments • • @ParameterizedClass @ValueSource(strings = {"foo", "bar"}) record

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

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

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

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