Annotation Interface EnumSource


@Target({ANNOTATION_TYPE,METHOD,TYPE}) @Retention(RUNTIME) @Documented @Inherited @Repeatable(EnumSources.class) @API(status=STABLE, since="5.7") @ArgumentsSource(org.junit.jupiter.params.provider.EnumArgumentsProvider.class) public @interface EnumSource
@EnumSource is a repeatable ArgumentsSource for constants of an Enum.

The enum constants will be provided as arguments to the annotated @ParameterizedClass or @ParameterizedTest.

The enum type can be specified explicitly using the value() attribute. Otherwise, the declared type of the first parameter of the @ParameterizedClass or @ParameterizedTest is used.

The set of enum constants can be restricted via the names(), from(), to() and mode() attributes.

Inheritance

This annotation is inherited to subclasses.

Since:
5.0
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enumeration of modes for selecting enum constants by name.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The starting enum constant of the range to be included.
    The enum constant selection mode.
    The names of enum constants to provide, or regular expressions to select the names of enum constants to provide.
    The ending enum constant of the range to be included.
    Class<? extends Enum<?>>
    The enum type that serves as the source of the enum constants.
  • Element Details

    • value

      Class<? extends Enum<?>> value
      The enum type that serves as the source of the enum constants.

      If this attribute is not set explicitly, the declared type of the first parameter of the @ParameterizedTest method is used.

      See Also:
      Default:
      org.junit.jupiter.params.provider.NullEnum.class
    • names

      String[] names
      The names of enum constants to provide, or regular expressions to select the names of enum constants to provide.

      If no names or regular expressions are specified, and neither from() nor to() are specified, all enum constants declared in the specified enum type will be provided.

      If from() or to() are specified, the elements in names must fall within the range defined by from() and to().

      The mode() determines how the names are interpreted.

      See Also:
      Default:
      {}
    • from

      @API(status=MAINTAINED, since="5.13.3") String from
      The starting enum constant of the range to be included.

      Defaults to an empty string, where the range starts from the first enum constant of the specified enum type.

      Since:
      5.12
      See Also:
      Default:
      ""
    • to

      @API(status=MAINTAINED, since="5.13.3") String to
      The ending enum constant of the range to be included.

      Defaults to an empty string, where the range ends at the last enum constant of the specified enum type.

      Since:
      5.12
      See Also:
      Default:
      ""
    • mode

      The enum constant selection mode.

      The mode only applies to the names() attribute and does not change the behavior of from() and to(), which always define a range based on the natural order of the enum constants.

      Defaults to INCLUDE.

      See Also:
      Default:
      INCLUDE