@ValueSource and @EnumSource

Learn how to use the @ValueSource and @EnumSource arguments in JUnit 5.

Argument sources

The key aspect of parameterized tests is how to provide the arguments. JUnit 5 has some built-in sources of arguments. We can also use the extension model to create our own sources:

  • @ValueSource
  • @EnumSource
  • @MethodSource
  • @CsvSource
  • @ArgumentsSource

The @ValueSource argument

We already used @ValueSource in the previous lesson. It provides an array of literals of type String, int, long, or double, which can be specified using the strings, ints, longs, or doubles attributes, respectively.

Get hands-on with 1400+ tech skills courses.