Parameterized Test with @ValueSource

This lesson demonstrates use of @ValueSource to pass different arguments to @ParameterizedTest.

We'll cover the following


@ValueSource is one of the simplest ways to pass arguments array to @ParameterizedTest method. This array can be of following types -

  1. short
  2. byte
  3. int
  4. long
  5. float
  6. double
  7. char
  8. java.lang.String
  9. java.lang.Class

Let’s look into a demo.

Step 1 - Let’s create a class, it is our class under test.

Step 2 - To this class we provide a method by name isNumberEven(). This method takes in an integer value and returns true if the number is even or false if the number is odd.

Get hands-on with 1200+ tech skills courses.