I'm currently creating a unit custom JUnit runner (which will precisely call custom code before/after each test method) e.g.
class MyRunner extends BlockJUnit4ClassRunner {
private MyApi api = new MyApi();
public MyRunner(Class<?> klass) throws InitializationError {
super(klass);
}
// todo
}
However, I would like to support other runners e.g. MockitoJunitRunner
and SpringRunner
, so instead of reinventing the wheel, I'd like to use my runner like the following (using a custom MyConfig
annotation to specify existing test runners): -
@RunWith(MyRunner.class)
@MyConfig(testRunner=MockitoJUnitRunner.class)
public class MockitoRunnerTest {
}
... or ...
@RunWith(MyRunner.class)
@MyConfig(testRunner=SpringRunner.class)
public class MockitoRunnerTest {
}
This means the test runner is very light i.e. it's like a Junit rule and simply proxies to another existing Junit runner after calling it's own code.
My gut feeling is that this has already be implemented/solved - just having problems finding it.
NOTE: I want to avoid using rules due to these problems - see Apply '@Rule' after each '@Test' and before each '@After' in JUnit
@Before
method (and creating thissetup
method if it doesn't exist) and also calling the code inside an@After
method (and also creating thistearDown
method if it doesn't exist). Really looking for a more DRY solution but agree that delegating to another existing (more established) runner likeSpringRunner
isn't ideal either. Trying to call the API of this open source project - github.com/videofirst/vft-capture – Chapell