Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Subclassing parameterized JUnit test



I am trying to subclass a Junit class to be used a ‘harness’ for parameterizing tests. I Want to subsclass a class that looks like

@RunWith(Parameterized.class)
public class A {
@Parameters
public Collection data() {
return overrideableMethod();
}

}

Subclass

public class B extends A {
@Override
public Object[] overrideableMethod() {
// change list of parmeters
}
@Test a() {
}
}

However, this seems not to be possible due to Java treating the @Parameters annotation. Also, since data() has to be static, I cannot override it with a non static method. I guess it is not allowed to override static methods anyway.

My main objective is to simplify subclasses so that they don’t have to use the @Parameters and @RunWith annotations, and automatically get benefit of some standard parameters built into the base class

Any tips / ideas?