Skip to content

Commit

Permalink
Introduce support for parameterized classes (#4342)
Browse files Browse the repository at this point in the history
This commit introduces @ParameterizedClass which builds on
@ContainerTemplate and allows declaring a top-level or @nested test
class as a parameterized container to be invoked multiple times with
different arguments. The same @...Source annotations as for
@ParameterizedTest may be used to provide arguments via constructor or
field injection.

Resolves #878.
  • Loading branch information
marcphilipp authored Feb 28, 2025
1 parent 8cab7b8 commit c4faa6c
Show file tree
Hide file tree
Showing 106 changed files with 4,964 additions and 1,074 deletions.
5 changes: 5 additions & 0 deletions documentation/src/docs/asciidoc/link-attributes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ endif::[]
:params-provider-package: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/provider/package-summary.html[org.junit.jupiter.params.provider]
:AnnotationBasedArgumentConverter: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/converter/AnnotationBasedArgumentConverter.html[AnnotationBasedArgumentConverter]
:AnnotationBasedArgumentsProvider: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/provider/AnnotationBasedArgumentsProvider.html[AnnotationBasedArgumentsProvider]
:AggregateWith: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/aggregator/AggregateWith.html[@AggregateWith]
:Arguments: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/provider/Arguments.html[Arguments]
:ArgumentsProvider: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/provider/ArgumentsProvider.html[ArgumentsProvider]
:ArgumentsAccessor: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/aggregator/ArgumentsAccessor.html[ArgumentsAccessor]
:ArgumentsAggregator: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/aggregator/ArgumentsAggregator.html[ArgumentsAggregator]
:CsvArgumentsProvider: {junit5-repo}/blob/main/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java[CsvArgumentsProvider]
Expand All @@ -193,6 +196,8 @@ endif::[]
:MethodSource: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/provider/MethodSource.html[@MethodSource]
:NullAndEmptySource: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/provider/NullAndEmptySource.html[@NullAndEmptySource]
:NullSource: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/provider/NullSource.html[@NullSource]
:Parameter: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/Parameter.html[@Parameter]
:ParameterizedClass: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/ParameterizedClass.html[@ParameterizedClass]
:ParameterizedTest: {javadoc-root}/org.junit.jupiter.params/org/junit/jupiter/params/ParameterizedTest.html[@ParameterizedTest]
:ValueArgumentsProvider: {junit5-repo}/blob/main/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/ValueArgumentsProvider.java[ValueArgumentsProvider]
// Jupiter Engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ repository on GitHub.
allow declaring a top-level or `@Nested` test class as a template to be invoked multiple
times. This may be used, for example, to inject different parameters to be used by all
tests in the container template class or to set up each invocation of the container
template differently.
template differently. Please refer to the
<<../user-guide/index.adoc#writing-tests-container-templates, User Guide>> for details.
* Introduce `@ParameterizedClass` concept that builds on `@ContainerTemplate` and allows
declaring a top-level or `@Nested` test class as a parameterized test class to be
invoked multiple times with different arguments. The same `@...Source` annotations as
for `@ParameterizedTest` may be used to provide arguments via constructor or field
injection. Please refer to the
<<../user-guide/index.adoc#writing-tests-parameterized-tests, User Guide>> for details.
* New `TestTemplateInvocationContext.prepareInvocation(ExtensionContext)` callback method
allows preparing the `ExtensionContext` before the test template method is invoked. This
may be used, for example, to store entries in its `Store` to benefit from its cleanup
Expand Down
2 changes: 1 addition & 1 deletion documentation/src/docs/asciidoc/user-guide/appendix.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Please refer to the corresponding sections for <<running-tests-build-maven-bom,
`junit-jupiter-engine`::
JUnit Jupiter test engine implementation; only required at runtime.
`junit-jupiter-params`::
Support for <<writing-tests-parameterized-tests,parameterized tests>> in JUnit Jupiter.
Support for <<writing-tests-parameterized-tests>> in JUnit Jupiter.
`junit-jupiter-migrationsupport`::
Support for migrating from JUnit 4 to JUnit Jupiter; only required for support for
JUnit 4's `@Ignore` annotation and for running selected JUnit 4 rules.
Expand Down
7 changes: 5 additions & 2 deletions documentation/src/docs/asciidoc/user-guide/extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,9 @@ implementing different kinds of tests that rely on repetitive invocation of _all
methods in a test class albeit in different contexts — for example, with different
parameters, by preparing the test class instance differently, or multiple times without
modifying the context.
Please refer to the implementations of
<<writing-tests-parameterized-tests, Parameterized Classes>> which uses this extension
point to provide its functionality.

[[extensions-test-templates]]
=== Providing Invocation Contexts for Test Templates
Expand Down Expand Up @@ -839,8 +842,8 @@ implementing different kinds of tests that rely on repetitive invocation of a te
method albeit in different contexts — for example, with different parameters, by preparing
the test class instance differently, or multiple times without modifying the context.
Please refer to the implementations of <<writing-tests-repeated-tests>> or
<<writing-tests-parameterized-tests>> which use this extension point to provide their
functionality.
<<writing-tests-parameterized-tests, Parameterized Tests>> which use this extension point
to provide their functionality.

[[extensions-keeping-state]]
=== Keeping State in Extensions
Expand Down
Loading

0 comments on commit c4faa6c

Please sign in to comment.