I'm trying to create test automation suite using JUnit. For all the tests, I want to create a Rule, for this I have created an Interface and placed the Rule inside it. Any tests that I want to run will have to implent that interface. It didn't throw any compiler error, however, when my Test class implements that interface, this doesn't seem to work. Following is the Interface I created.
public interface IBaseTest {
@Rule
public TestRule test = new TestWatcher(){
@Override
protected void starting(Description description)
{
System.out.println("Starting Test: " + description);
}
};
}
Alternatively, I could have created the above as a class and extend all my test classes from that class, I tried that and it worked perfectly, however this would prevent me from extending my test methods from any other class.
Is there a way for me to create rules that will be applicable for all my tests without extending from a base class?