Close

JUnit 5 - @ParameterizedTest with Named Interface

[Last Updated: Dec 30, 2025]

The Named interface in JUnit 5 allows developers to associate a custom display name with a specific argument value. This is particularly useful when the raw value of the argument (like a complex object or a null value) does not provide a descriptive or readable string representation in the test execution reports.

Java source and doc

Definition of Named

Version: 6.0.0
 package org.junit.jupiter.api;
 @API(status = STABLE, since = "5.8")
 public interface Named<T extends @Nullable Object> {
     static <T extends @Nullable Object> Named<T> of(String name, T payload) { 1
         ...
     }
     static <T extends @Nullable Object> Named<T> named(String name, T payload) { 2
         ...
     }
     String getName(); 3
     T getPayload(); 4
 }
1Factory method for creating an instance of Named based on a name and a payload.
2Factory method for creating an instance of Named based on a name and a payload.
3Get the name of the payload.
4Get the payload.

What is payload?

A payload refers to the actual data or object being tested in a parameterized test.

When using the Named<T> interface, the payload is the underlying value you want to pass to your test method, while the name is a human-readable description used for display purposes in your IDE or test reports.

Example

In the following example, we use Named.of(String, T) to wrap our test data. Instead of seeing the default string representation in the IDE or build logs, the provided labels will be displayed.

package com.logicbig.example;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Named;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;

public class ParameterizedNamedTest {

    @ParameterizedTest
    @MethodSource("namedArguments")
    void testWithNamedInterface(String input) {
        System.out.println("Testing: " + input);
        Assertions.assertNotNull(input);
    }

    static Stream<Named<String>> namedArguments() {
        return Stream.of(
                Named.of("Upper case string", "ABC"),
                Named.of("Lower case string", "abc")
        );
    }
}

Output

$ mvn test -Dtest=ParameterizedNamedTest
[INFO] Scanning for projects...
[INFO]
[INFO] -----< com.logicbig.example:junit-5-parameterized-named-interface >-----
[INFO] Building junit-5-parameterized-named-interface 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ junit-5-parameterized-named-interface ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\example-projects\junit-5\junit-5-parameterized-tests\junit-5-parameterized-named-interface\src\main\resources
[INFO]
[INFO] --- compiler:3.13.0:compile (default-compile) @ junit-5-parameterized-named-interface ---
[INFO] No sources to compile
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ junit-5-parameterized-named-interface ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\example-projects\junit-5\junit-5-parameterized-tests\junit-5-parameterized-named-interface\src\test\resources
[INFO]
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ junit-5-parameterized-named-interface ---
[INFO] Recompiling the module because of added or removed source files.
[WARNING] File encoding has not been set, using platform encoding windows-1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file with javac [debug target 17] to target\test-classes
[INFO]
[INFO] --- surefire:3.5.0:test (default-test) @ junit-5-parameterized-named-interface ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
Testing: ABC
Testing: abc
[INFO] +--com.logicbig.example.ParameterizedNamedTest - 0.171 ss
[INFO] | +-- [OK] testWithNamedInterface(String)[1] Upper case string - 0.041 ss
[INFO] | '-- [OK] testWithNamedInterface(String)[2] Lower case string - 0.001 ss
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.787 s
[INFO] Finished at: 2025-12-28T13:15:19+08:00
[INFO] ------------------------------------------------------------------------

Output Analysis

The output of the test execution demonstrates that the test reports use the labels "Upper case string" and "Lower case string" instead of the actual string values. This confirms that the Named interface effectively decouples the test data from its visual representation, making complex test suites much easier to debug and audit.

Example Project

Dependencies and Technologies Used:

  • junit-jupiter-engine 6.0.1 (Module "junit-jupiter-engine" of JUnit)
     Version Compatibility: 5.0.0 - 6.0.1Version List
    ×

    Version compatibilities of junit-jupiter-engine with this example:

    • 5.0.0
    • 5.0.1
    • 5.0.2
    • 5.0.3
    • 5.1.0
    • 5.1.1
    • 5.2.0
    • 5.3.0
    • 5.3.1
    • 5.3.2
    • 5.4.0
    • 5.4.1
    • 5.4.2
    • 5.5.0
    • 5.5.1
    • 5.5.2
    • 5.6.0
    • 5.6.1
    • 5.6.2
    • 5.6.3
    • 5.7.0
    • 5.7.1
    • 5.7.2
    • 5.8.0
    • 5.8.1
    • 5.8.2
    • 5.9.0
    • 5.9.1
    • 5.9.2
    • 5.9.3
    • 5.10.0
    • 5.10.1
    • 5.10.2
    • 5.10.3
    • 5.10.4
    • 5.10.5
    • 5.11.0
    • 5.11.1
    • 5.11.2
    • 5.11.3
    • 5.11.4
    • 5.12.0
    • 5.12.1
    • 5.12.2
    • 5.13.0
    • 5.13.1
    • 5.13.2
    • 5.13.3
    • 5.13.4
    • 5.14.0
    • 5.14.1
    • 6.0.0
    • 6.0.1

    Versions in green have been tested.

  • junit-jupiter-params 6.0.1 (Module "junit-jupiter-params" of JUnit)
  • JDK 25
  • Maven 3.9.11

JUnit 5 - Parameterized Named Interface Select All Download
  • junit-5-parameterized-named-interface
    • src
      • test
        • java
          • com
            • logicbig
              • example
                • ParameterizedNamedTest.java

    See Also