ParameterizedTest with @MethodSource

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

We'll cover the following

@MethodSource

@MethodSource allows us to specify a factory method for different test arguments. This factory method must be static and can be present in the same class or any other class too. The factory method should return Stream, Iterator, Iterable or array of elements to @ParameterizedTest method.

Let’s look at a demo.

Step 1 - Let’s assume that we have to write a parameterized test that takes values of the static factory method as @MethodSource.

Get hands-on with 1200+ tech skills courses.