jUnit ignore @Test methods from base class

and I don't overwrite anything. testFixtureAB is empty as for now

There's your answer. If you want to not run testB from the main class, overrride it:

public class testFixtureAB extends testFixtureA {
   @Override
   public void testB() {}
}

It's quite easy to achieve implementing some few classes:

  • Create your own TestRunner
  • Create an annotation like @IgnoreInheritedTests
  • Create a class that extends org.junit.runner.manipulation.Filter

On the filter class:

public class InheritedTestsFilter extends Filter {

    @Override
    public boolean shouldRun(Description description) {
        Class<?> clazz = description.getTestClass();
        String methodName = description.getMethodName();
        if (clazz.isAnnotationPresent(IgnoreInheritedTests.class)) {
            try {
                return clazz.getDeclaredMethod(methodName) != null;
            } catch (Exception e) {
                return false;
            }
        }
        return true;
    }

    @Override
    public String describe() {
        // TODO Auto-generated method stub
        return null;
    }

}

on your custom runner:

 /**
 * @param klass
 * @throws InitializationError
 * @since
 */
public CustomBaseRunner(Class<?> klass) throws InitializationError {
    super(klass);
    try {
        this.filter(new InheritedTestsFilter());
    } catch (NoTestsRemainException e) {
        throw new IllegalStateException("class should contain at least one runnable test", e);
    }
}

Restructure your test classes.

  • If you don't want to use the tests from the baseclass, then don't extend it
  • If you need other functionality from the base class, split that class in two - the tests, and the other functionality

ignoring the whole base class:

@Ignore
class BaseClass {
   // ...
}

check out this example