Using test rules for JUnit3 TestCase

784 views Asked by At

First of all let me explain the test setup,

I work for this very large project which has many smaller modules. And to test, we use JUnit in two ways,

  • JUnit 4: With @Test annotation and we use a custom test runner that derives from BlockJunit4ClassRunner
  • JUnit 3: We a large chunk of tests those are dynamically created from XML files and are based on junit.framework.TestCase. We have a custom test runner for this too that inherits org.junit.runners.AllTests.

For some cross cutting non-functional requirements we have implemented some rules (org.junit.rules) which we use through annotating the test class using @Rule. This works well for JUnit4 but not JUnit3.

Is there a straight forward way of implementing it without making too many changes?

In case of BlockJunit4ClassRunner we have FrameworkMethod,

@Override
protected void runChild(final FrameworkMethod method, RunNotifier     notifier) {  
...
}

However in case of AllTests, we don't have,

@Override
public void run(RunNotifier notifier) {
...
...
}
0

There are 0 answers