I want only some subset of my test methods to run on a production environment. I annotate such test methods with @ProdAllowed annotation. I also wrote a small custom JUnit runner, which overrides the runChild method so it runs only for @ProdAllowed methods while on "PROD" environment:
public class ProdAwareRunner extends BlockJUnit4ClassRunner { public ProdAwareRunner(Class<?> klass) throws InitializationError { super(klass); } @Override protected void runChild(FrameworkMethod method, RunNotifier notifier) { ProdAllowed annotation = method.getAnnotation(ProdAllowed.class); String env = CreditCheckSuite.getEnv().trim(); if (annotation != null || "DEV".equalsIgnoreCase(env) || "UAT".equalsIgnoreCase(env)) { super.runChild(method, notifier); } else { notifier.fireTestIgnored(null); // this probably needs to be changed } } } This works quite well, but I want a little more - to have this skipped test methods to be marked in Eclipse as ignored (right now they are marked as not run, which is not exactly what I want)