JUnit 5 Parameterized Tests - @ParameterizedTest
How to pass multiple parameters to one test method
Overview
@ParameterizedTest lets one test method run with multiple parameters.
Adding Dependencies
To use @ParameterizedTest, add the junit-jupiter-params library.
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.1'
}
@ValueSource
@ValueSource specifies a single array of literal values. It is used when each parameterized test invocation receives one argument.
Null and Empty Sources
@NullSource and @EmptySource provide null and empty values respectively. They can be combined with @ValueSource.
@NullAndEmptySource is a composed source used when both @NullSource and @EmptySource are needed. It can also be combined with @ValueSource.
@EnumSource
@EnumSource is used to pass enum values as parameters.
@MethodSource
@MethodSource is used when parameters are provided by a method. The provider method can return a Stream of Arguments.