Annotation Type MethodSource


  • @Target({ANNOTATION_TYPE,METHOD})
    @Retention(RUNTIME)
    @Documented
    @API(status=EXPERIMENTAL,
         since="5.0")
    @ArgumentsSource(org.junit.jupiter.params.provider.MethodArgumentsProvider.class)
    public @interface MethodSource
    @MethodSource is an ArgumentsSource which provides access to values returned from factory methods of the class in which this annotation is declared or from static factory methods in external classes referenced by fully qualified method name.

    Each factory method must return a Stream, Iterable, Iterator, or array of arguments. The returned values will be provided as arguments to the annotated @ParameterizedTest method. If the parameterized test has a single parameter, each factory method may return value instances, e.g. as Stream<String> for a single String parameter, directly. If a parameterized test method declares multiple parameters, factory methods must return instances of Arguments, e.g. as Stream<Arguments>.

    Factory methods within the test class must be must be static unless the PER_CLASS test instance lifecycle mode is used; whereas, factory methods in external classes must always be static. In any case, factory methods must not declare any parameters.

    Since:
    5.0
    See Also:
    Arguments, ArgumentsSource, ParameterizedTest, TestInstance
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String[] value
      The names of factory methods within the test class or in external classes to use as sources for arguments.
    • Element Detail

      • value

        String[] value
        The names of factory methods within the test class or in external classes to use as sources for arguments.

        Factory methods in external classes must be referenced by fully qualified method name — for example, com.example.StringsProviders#blankStrings.

        If no factory method names are declared, a method within the test class that has the same name as the test method will be used as the factory method by default.

        For further information, see the class-level JavaDoc.

        Default:
        {""}