diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M1.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M1.adoc index a336a85b9121..66f05a2d8cc9 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M1.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M1.adoc @@ -111,7 +111,9 @@ page in the Wiki. the supplied message is not the _expected message_ of the thrown exception. * Improved documentation for semantics of a disabled test regarding class-level lifecycle methods and callbacks. - +* Support `@..Source` annotations as repeatable for parameterized tests. See the + <<../user-guide/index.adoc#writing-tests-parameterized-repeatable-sources, User Guide>> + for more details. [[release-notes-5.11.0-M1-junit-vintage]] === JUnit Vintage diff --git a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc index 756722623a2f..64fc734fb721 100644 --- a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc +++ b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc @@ -1963,6 +1963,34 @@ If you wish to implement a custom `ArgumentsProvider` that also consumes an anno (like built-in providers such as `{ValueArgumentsProvider}` or `{CsvArgumentsProvider}`), you have the possibility to extend the `{AnnotationBasedArgumentsProvider}` class. +[[writing-tests-parameterized-repeatable-sources]] +===== Multiple sources using repeatable annotations +Repeatable annotations allows you a convenient way to provide multiple sources from +different providers whenever it fits. + +[source,java,indent=0] +---- +include::{testDir}/example/ParameterizedTestDemo.java[tags=repeatable_annotations] +---- + +Following the above parameterized test, a test case will run for each argument: + +---- +[1] foo +[2] bar +---- + +Annotations that support repeatable capability: + +* `@ValueSource` +* `@EnumSource` +* `@MethodSource` +* `@FieldSource` +* `@CsvSource` +* `@CsvFileSource` +* `@ArgumentsSource` + + [[writing-tests-parameterized-tests-argument-conversion]] ==== Argument Conversion diff --git a/documentation/src/test/java/example/ParameterizedTestDemo.java b/documentation/src/test/java/example/ParameterizedTestDemo.java index 0ca33aec886d..1b94e053519a 100644 --- a/documentation/src/test/java/example/ParameterizedTestDemo.java +++ b/documentation/src/test/java/example/ParameterizedTestDemo.java @@ -542,4 +542,22 @@ static Stream namedArguments() { } // end::named_arguments[] // @formatter:on + + // tag::repeatable_annotations[] + @DisplayName("A parameterized test that makes use of repeatable annotations") + @ParameterizedTest + @MethodSource("someProvider") + @MethodSource("otherProvider") + void testWithRepeatedAnnotation(String argument) { + assertNotNull(argument); + } + + static Stream someProvider() { + return Stream.of("foo"); + } + + static Stream otherProvider() { + return Stream.of("bar"); + } + // end::repeatable_annotations[] }