Skip to content

Commit

Permalink
Add release notes and user guide section related to repeatable annota…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
Madalin Giurca authored and madalingiurca committed Apr 25, 2024
1 parent 4683659 commit 0acecf1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions documentation/src/docs/asciidoc/user-guide/writing-tests.adoc
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions documentation/src/test/java/example/ParameterizedTestDemo.java
Expand Up @@ -542,4 +542,22 @@ static Stream<Arguments> 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<String> someProvider() {
return Stream.of("foo");
}

static Stream<String> otherProvider() {
return Stream.of("bar");
}
// end::repeatable_annotations[]
}

0 comments on commit 0acecf1

Please sign in to comment.