Hello Sarfaraz, JUnit provides special kind of handling of tests or test suite by using @rule annotation. By using @rule, you can easily add or redefine the behavior of the test. There are several built-in rules provided by JUnit API that a tester can use, or even you can write our own rule. Following line of code shows how to use @rule annotation along with Error Collector:
@Rule
public ErrorCollector collector= new ErrorCollector();