@MethodSource

The annotation @MethodSource allows to define the name of the static method in which the arguments for the test are provided as a Java 8 Stream. For instance, in the following example, we can see a parameterized test in which the argument provider is a static method called stringProvider. In this example, this method returns a Stream of String's and therefore the argument of the test method (callled testWithStringProvider) accepts one String argument:

package io.github.bonigarcia;import static org.junit.jupiter.api.Assertions.assertNotNull;import java.util.stream.Stream;import org.junit.jupiter.params.ParameterizedTest;import org.junit.jupiter.params.provider.MethodSource;class MethodSourceStringsParameterizedTest {    static ...

Get Mastering Software Testing with JUnit 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.