This lesson introduces the
@ParameterizedTest, a viable option for declaring tests that require several different inputs. When a test method is annotated with this annotation (instead of the usual
@Test), it may accept arbitrary input data through its method parameters.
Where does this input data come from? It's stored in a particular kind of companion annotation, which sits alongside the
@ParameterizedTest. These companions are called "sources" in JUnit Jupiter, and the most straightforward source is explored here:
@ValueSource. You define an array of values inside the annotation, and during execution, the TestEngine will call the test method once for each item in this array. This works very well for primitive values and strings.
@ParameterizedTestmethod is executed multiple times; its parameters define the kind of data that it needs
@ParameterizedTestneeds a "source annotation" which provides the values