October 27th, 2008 Archive

Overriding the default Runner.

October 27th, 2008 by David Saff in Uncategorized

If you are running your JUnit 4.5 tests with a direct call to JUnitCore.run, you can override the default runner (BlockJUnit4ClassRunner) used to run tests that don’t otherwise have a @RunWith annotation:

RunnerBuilder builder = new AllDefaultPossibilitiesBuilder() { 
  @Override protected JUnit4Builder junit4Builder() {
    return new JUnit4Builder() {
      @Override public Runner runnerForClass(Class testClass) throws Throwable {
        return new MyCustomJUnit4ClassRunner(testClass);
      }
    };
  }
}

new JUnitCore().run(new Suite(AllMyTests.class, builder));