O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required