In the simplest case you can pass expected values as parameters and use them in assertions, as shown in javadoc.
In more complex cases you need to encapsulate assert logic into objects and pass them as parameters.
If you need different assertions for the same values you can use assertThat()
and Matcher<T>
:
class abcTest
{
@Parameters
public static Collection<Object[]> testParameters()
{
return Arrays.asList(new Object[][] {
{1, CoreMatchers.is(true)},
{2, CoreMatchers.is(false)}
});
}
..
@Test
public void test()
{
...
assertThat(value, matcher);
}
}
Otherwise, if different parameters need completely different assertions you can pass them as Runnable
s.
However, it may be not a good idea to use parameterized tests in this case - if you need completely different assertions for different cases it can be more elegant to create separate test methods for these cases, extracting their commons parts into helper methods:
@Test
public void shouldHandleCase1() {
handleCase(1);
assertTrue(...);
}
@Test
public void shouldHandleCase2() {
handleCase(2);
assertFalse(...);
}