[ https://issues.apache.org/jira/browse/SUREFIRE-1405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16242208#comment-16242208 ]
ASF GitHub Bot commented on SUREFIRE-1405: ------------------------------------------ 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 ---- > Allow provider to override default runOrder & RunOrderCalculator from > surefire-api > ---------------------------------------------------------------------------------- > > Key: SUREFIRE-1405 > URL: https://issues.apache.org/jira/browse/SUREFIRE-1405 > Project: Maven Surefire > Issue Type: Improvement > Components: Maven Surefire Plugin > Reporter: Dipak Pawar > Labels: features > Fix For: Backlog > > > * Currently surefire supports "alphabetical", "reversealphabetical", > "random", "hourly", "failedfirst", "balanced" and "filesystem" runOrder. > * All supported 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 > * There is no way for user to add new runOrder in new provider implemented by > him. > * Allow user to override/add new runOrder & RunOrderCalculator implementaion > so surefire-api will dynamically load all supported runOrder & decide which > RunOrderCalculator implementation to use for ordering test classes depending > on provided runOrders. -- This message was sent by Atlassian JIRA (v6.4.14#64029)