Search⌘ K
AI Features

@ValueSource and @EnumSource

Discover how to implement parameterized tests in JUnit 5 using @ValueSource to pass literals and @EnumSource to provide enum constants as test arguments. Understand how to limit or exclude enum constants with attributes and use regular expressions for advanced filtering.

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 ...