Interface Arguments

All Known Implementing Classes:
Arguments.ArgumentSet
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface @API(status=STABLE, since="5.7") public interface Arguments
Arguments is an abstraction that provides access to an array of objects to be used for the invocation of a @ParameterizedClass or @ParameterizedTest method.

A Stream of such Arguments will typically be provided by an ArgumentsProvider.

Since:
5.0
See Also:
API Note:

This interface is specifically designed as a simple holder of arguments for a parameterized test. Therefore, if you end up transforming or filtering the arguments, you should consider using one of the following in intermediate steps:

  • The standard Java collections
  • Tuples from third-party libraries — for example, Commons Lang or javatuples
  • Your own data class

Alternatively, you can use an ArgumentConverter to convert some of the arguments from one type to another.

  • Method Details

    • get

      @Nullable Object[] get()
      Get the arguments used for an invocation of the @ParameterizedClass or @ParameterizedTest method.
      Returns:
      the arguments; never null but may contain null
      API Note:
      If you need a type-safe way to access some or all of the arguments, please read the class-level API note.
    • toList

      @API(status=EXPERIMENTAL, since="6.1") default List<@Nullable Object> toList()
      Convert the arguments to a new mutable List containing the same elements as get().

      This is useful for test logic that benefits from List operations such as filtering, transformation, or assertions.

      Returns:
      a mutable List of arguments; never null but may contain null
      Since:
      6.1
    • of

      static Arguments of(@Nullable Object... arguments)
      Factory method for creating an instance of Arguments based on the supplied arguments.
      Parameters:
      arguments - the arguments to be used for an invocation of the test method; must not be null but may contain null
      Returns:
      an instance of Arguments; never null
      See Also:
    • from

      @API(status=EXPERIMENTAL, since="6.1") static Arguments from(Iterable<? extends @Nullable Object> arguments)
      Factory method for creating an instance of Arguments based on the supplied Iterable of arguments.

      The iterable supplied to this method should be a finite collection and have a reliable iteration order to provide arguments in a consistent order to tests. It is therefore recommended that the iterable be a SequencedCollection (on Java 21 or higher), List, or similar.

      Parameters:
      arguments - the arguments to be used for an invocation of the test method; must not be null but may contain null
      Returns:
      an instance of Arguments; never null
      Since:
      6.1
      See Also:
    • arguments

      static Arguments arguments(@Nullable Object... arguments)
      Factory method for creating an instance of Arguments based on the supplied arguments.

      This method is an alias for of(Object...) and is intended to be used when statically imported — for example, via: import static org.junit.jupiter.params.provider.Arguments.arguments;

      Parameters:
      arguments - the arguments to be used for an invocation of the test method; must not be null but may contain null
      Returns:
      an instance of Arguments; never null
      Since:
      5.3
      See Also:
    • argumentsFrom

      @API(status=EXPERIMENTAL, since="6.1") static Arguments argumentsFrom(Iterable<? extends @Nullable Object> arguments)
      Factory method for creating an instance of Arguments based on the supplied Iterable of arguments.

      This method is an alias for from(Iterable) and is intended to be used when statically imported — for example, via: import static org.junit.jupiter.params.provider.Arguments.argumentsFrom;

      The iterable supplied to this method should be a finite collection and have a reliable iteration order to provide arguments in a consistent order to tests. It is therefore recommended that the iterable be a SequencedCollection (on Java 21 or higher), List, or similar.

      Parameters:
      arguments - the arguments to be used for an invocation of the test method; must not be null but may contain null
      Returns:
      an instance of Arguments; never null
      Since:
      6.1
      See Also:
    • argumentSet

      @API(status=MAINTAINED, since="5.13.3") static Arguments.ArgumentSet argumentSet(String name, @Nullable Object... arguments)
      Factory method for creating an Arguments.ArgumentSet based on the supplied name and arguments.

      Favor this method over Arguments.of(...) and arguments(...) when you wish to assign a name to the entire set of arguments.

      This method is well suited to be used as a static import — for example, via: import static org.junit.jupiter.params.provider.Arguments.argumentSet;.

      Parameters:
      name - the name of the argument set; must not be null or blank
      arguments - the arguments to be used for an invocation of the test method; must not be null but may contain null
      Returns:
      an ArgumentSet; never null
      Since:
      5.11
      See Also:
    • argumentSetFrom

      @API(status=EXPERIMENTAL, since="6.1") static Arguments.ArgumentSet argumentSetFrom(String name, Iterable<? extends @Nullable Object> arguments)
      Factory method for creating an Arguments.ArgumentSet based on the supplied name and Iterable of arguments.

      Favor this method over Arguments.from(...) and argumentsFrom(...) when you wish to assign a name to the entire set of arguments.

      This method is well suited to be used as a static import — for example, via: import static org.junit.jupiter.params.provider.Arguments.argumentSetFrom;.

      The iterable supplied to this method should be a finite collection and have a reliable iteration order to provide arguments in a consistent order to tests. It is therefore recommended that the iterable be a SequencedCollection (on Java 21 or higher), List, or similar.

      Parameters:
      name - the name of the argument set; must not be null or blank
      arguments - the arguments to be used for an invocation of the test method; must not be null but may contain null
      Returns:
      an ArgumentSet; never null
      Since:
      6.1
      See Also: