GitHub user dipak-pawar opened a pull request: https://github.com/apache/maven-surefire/pull/169
[SUREFIRE-1405] Allows user to extend RunOrder & RunOrderCalculator * All supported runOrder options are hardCoded in RunOrder - https://github.com/apache/maven-surefire/blob/master/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java#L109 * With this implementation user can implement his own runOrder & it's respective RunOrderCalculator. Fixes: https://issues.apache.org/jira/browse/SUREFIRE-1405 **Implementation Details** **How to create new RunOrder?** To create new `runOrder` user has to implement `RunOrder` interface. ```java public class YourRunOrder implements RunOrder { @Override public String getName() { return "runOrderName"; } @Override public List<Class<?>> orderTestClasses( Collection<Class<?>> scannedClasses, RunOrderParameters runOrderParameters, int threadCount ) { // Add logic to order test classes for this runOrder. return testClasses; } } ``` **How to define custom RunOrderCalculator?** Implement `RunOrderCalculator` interface with logic you want to order test classes. e.g. ```java public class YourRunOrderCalculator implements RunOrderCalculator { private final RunOrderParameters runOrderParameters; private final int threadCount; private final RunOrder[] runOrder; public YourRunOrderCalculator(RunOrderParameters runOrderParameters, int threadCount) { this.runOrder = runOrderParameters.getRunOrders(); this.runOrderParameters = runOrderParameters; this.threadCount = threadCount; } // Add your logic to order test classes. @Override public TestsToRun orderTestClasses(TestsToRun scannedClasses) { List<Class<?>> testClasses = new ArrayList<Class<?>>( 512 ); for ( Class<?> scannedClass : scannedClasses ) { testClasses.add( scannedClass ); } final Collection<Class<?>> classes = runOrder[0].orderTestClasses(testClasses, runOrderParameters, threadCount); return new TestsToRun(new LinkedHashSet<>(classes)); } } ``` **How to tell surefire to use custom `RunOrder` & `RunOrderCalculator`?** We have `RunOrderProvider` spi to overwrite default runOrders & `RunOrderCalculator` provided by surefire. You need to registrar impl of RunOrderProvider in the file named `META-INF/services/org.apache.maven.plugin.surefire.runorder.spi.RunOrderProvider` in main resources. File should contain fully qualified name of RunOrderProvider impl. e.g. `com.surefire.YourRunOrderProviderImpl` Implementation of YourRunOrderProviderImpl is as follows: ```java public class YourRunOrderProviderImpl implements RunOrderProvider { @Override public Collection<RunOrder> getRunOrders() { // here you can give all default runorders provided by surefire along with custom runorder created above. return Arrays.asList( ALPHABETICAL, FILESYSTEM, HOURLY, RANDOM, REVERSE_ALPHABETICAL, BALANCED, FAILEDFIRST, new YourRunOrder() ); } @Override public Integer priority() { return 1; } @Override public RunOrderCalculator createRunOrderCalculator( RunOrderParameters runOrderParameters, int threadCount ) { return new YourRunOrderCalculator( runOrderParameters, threadCount ); } @Override public Collection<RunOrder> defaultRunOrder() { return Collections.singletonList( FILESYSTEM ); } } ``` You can merge this pull request into a Git repository by running: $ git pull https://github.com/dipak-pawar/maven-surefire surefire_improvement Alternatively you can review and apply these changes as the patch at: https://github.com/apache/maven-surefire/pull/169.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #169 ---- commit 6735b1ef750c3bcd613d5998a313e5007dc37349 Author: Dipak Pawar <dpa...@redhat.com> Date: 2017-08-23T15:33:08Z [SUREFIRE-1405] Allows user to extend RunOrder & RunOrderCalculator ---- --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org