I would like to do something like this in jUnit:
@Runwith(Parameterized.class)
public abstract class BaseTest {
protected abstract List<Object[]> extraParams();
protected abstract ClassUnderTest testObject;
@Parameters
public Collection<Object[]> data() {
List<Object> params = ...;
params.addAll(extraParams());
return params;
}
@Test
public doTest() {
}
}
public class ConcreteTest extends BaseTest {
protected ClassUnderTest = new ConcreteClass(...);
protected List<Object[]) extraParams() {
List<Object> extraParams = ...;
return extraParams;
}
}
Thus, expanding this class, I run a bunch of standard tests against the test object, as well as some additional ones specified in a particular class.
However, jUnit requires the method to @Parametersbe static. How else can I accurately achieve the goal, have a set of standard parameters plus additional ones in specific classes?
The best thing I've come up with so far is to have un-annotated Collection<Object[]> standardParams()in an abstract class and require the subclass to contain the method:
@Parameters
public Collection<Object[]> data() {
List<Object> params = standardParams();
params.addAll(...);
return params;
}
... but this is not as neat as we would like, since he bears too much responsibility for the author of the subclass.