JUnitParams provides a JUnitParamsRunner that allows you to pass parameters directly into your test method arguments using the @Parameters annotation. This is more concise than standard JUnit 4 parameterised tests because it avoids the need for class-level fields and constructors.
Key features:
- Parameters are passed directly to the test method parameters.
- You can mix parameterised and non-parameterised methods in the same class.
- Parameters can be provided as a CSV string via
@Parameters or from a dedicated provider class. - You can use a method within the same test class to provide parameters.
@RunWith(JUnitParamsRunner.class)
public class PersonTest {
@Test
@Parameters({"17, false",
"22, true" })
public void personIsAdult(int age, boolean valid) throws Exception {
assertThat(new Person(age).isAdult(), is(valid));
}
}