Search⌘ K
AI Features

ParameterizedTest with @MethodSource

Understand how to create parameterized tests in JUnit 5 using the @MethodSource annotation. Learn to supply multiple test arguments from a static factory method returning streams, collections, or arrays to run a test method multiple times with different inputs.

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