junit-parameters enables adding parameters to JUnit 4 test methods.
- Annotate your test class with the
JUnitParameters
test runner:
@RunWith(JUnitParameters.class)
public class ParametersGeneratorTest {
}
- Implement the interface
ParameterGenerator
:
public class OneParameterGenerator implements ParameterGenerator {
@Override
public Iterable<Object[]> parameters() {
return Arrays.asList(new Object[][] { { "foo" }, { "bar" },
{ "baz" }, { "code" },
{ "java" } });
}
}
- Use it in your test with the
@ParameterProvider
annotation
@Test
@ParameterProvider(OneParameterGenerator.class)
public void injectSingleParam(String parameter) {
}
The JUnit test method will be invoked with each parameter created by the ParameterGenerator
factory used in the test.
There are some tests available at src/test/java
. It's possible to run the JUnitParametersTest
test class and see the results.
junit-parameters is licensed under the The MIT License (MIT)