Parameterized Tests

Learn parameterized tests in JUnit 5.

JUnit 5 allows a test to run multiple times with different arguments. They are declared like the normal tests, but we use the @ParameterizedTest annotation instead of the @Test annotation. This is helpful to test our method with various input data.

To run a parameterized test, we declare at least one Source that provides an argument for each function call. This is then passed to the test method.

Setup

To enable parameterized tests, we add the junit-jupiter-params dependency artifact.

To use this in Maven, we add the below dependency to the pom.xml file:

Get hands-on with 1400+ tech skills courses.