title: Easier Way to Apply a Custom JUnit Test Runner on hundreds of Java test classes
body: <p>We have a few hundreds of tests in our project, and we now need to run them all with a custom test runner. We have written a custom test runner, called RetryRunner, that retries a failing test for a configurable maximum number of attempts. The code for RetryRunner was taken from here: <a href="https://stackoverflow.com/questions/8295100/how-to-re-run-failed-junit-tests-immediately">How to Re-run failed JUnit tests immediately?</a></p>
  
  <p>Now, to run a test class with this RetryRunner, we either have the option of:</p>
  
  <p>1.</p>
  
  <p>@RunWith(CustomSuite.class)</p>
  
  <p>@Suite.SuiteClasses({
          TestClass1.class,
          TestClass2.class
  })</p>
  
  <p>where CustomSuite.class returns our RetryRunner, so that the test retry mechanism is applied on TestClass1 and TestClass2. (Note: Some of our tests are indeed a part of @Suite.SuiteClasses)</p>
  
  <p>OR</p>
  
  <p>2.</p>
  
  <p>@RunWith(RetryRunner.class)
  public class SampleTestClass {...}</p>
  
  <p>which will enable all tests in SampleTestClass to be run with RetryRunner. And we similarly keep using @RunWith(RetryRunner.class) for every test class.</p>
  
  <p>Now, although we would have loved to keep all our tests within @Suite.SuiteClasses, it is currently not practical since we have many modules in our project and most of our tests comply with the module_name-->src-->test directory structure that maven requires to run tests. These tests are therefore not within @Suite.SuiteClasses, and maven automatically picks them and runs them at runtime.</p>
  
  <p>My question is, how do I apply our RetryRunner on all our test classes that are not a part of @Suite.SuiteClasses? Since we have hundreds of test classes, going to each test class and prepending it with @RunWith(RetryRunner.class) would be our least preferred option since it is quite cumbersome.</p>
  
  <p>Question1: Is there a way to pass RetryRunner as a maven command line arg in such a way that it will replace the normal Runner for all test classes?</p>
  
  <p>Question2: Or is there a way to configure RetryRunner in the main project pom.xml so that it will be used on all test classes?</p>