Hey Ekanshi, Error collector collects all error objects and reports it only once after the test execution is over. The benefit of adding all errors in an Error Collector is that you can verify all the errors at once. Also, if the script fails in the middle, it can still continue executing it. If you want to execute all the tests even if any line of code fails due to network failure, assertion failure, or any other reason, you can still continue executing test script using a special feature provided by JUnit known as "error collector".
JUnit uses @Rule annotation which is used to create an object of error collector. Once the object for error collector is created, you can easily add all the errors into the object using method addError (Throwable error). As we know that Throwable is the super class of Exception and Error class in Java. When you add errors in this way, these errors will be logged in JUnit test result .