Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling Surefire to run test classes and test methods in any order specified #2

Open
wants to merge 30 commits into
base: umaster
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8a6b334
[SUREFIRE-1432] Add extension interface with two implementations for …
dfa1 Apr 2, 2019
125c043
adds a new configuration option, 'methodRunOrder' (or -Dsurefire.meth…
jon-bell Apr 11, 2020
7da3a98
also add a bunch of hacks that look less pretty
jon-bell Apr 13, 2020
b062f9f
Bump version
jon-bell Apr 14, 2020
d0163cf
Updating plugin.
winglam Jul 21, 2020
ab5a081
Finalized features to run more than 2 tests, cleaned up arguments to …
OrDTesters Jul 21, 2020
8f35368
Adding surefire-changing maven extension.
OrDTesters Jul 21, 2020
6fc2515
Adding todos.
OrDTesters Jul 21, 2020
4954fd1
Cleaning readme.
OrDTesters Jul 21, 2020
65a6f64
Removing extra space.
OrDTesters Jul 21, 2020
12c5ae8
Improving readme.
OrDTesters Jul 27, 2020
d51e26f
Merge branch 'release/3.0.0-M6' into test-method-sorting
jon-bell Sep 1, 2020
a1ed458
Merge
jon-bell Sep 1, 2020
bd1946f
adding issues.
winglam Oct 9, 2020
2e95d6b
Merging.
winglam Oct 9, 2020
69c5a0a
Merging with surefire master.
winglam Oct 9, 2020
2302c41
Fixing issue with fixing method order.
winglam Oct 9, 2020
87b62ce
Removing remaining randomSeeds.
winglam Oct 9, 2020
2490a4b
Improving readme.
winglam Oct 9, 2020
320efe9
Updating issues.
winglam Oct 9, 2020
e2ed417
Updating readme to clarify usage of path_to_file
winglam Oct 28, 2020
8162cb5
Updating README instructions about branch
Dec 1, 2020
e2184c6
Adding information that may help locate Maven installation
Dec 6, 2020
f191e23
Fix for controlling test class ordering.
winglam Feb 20, 2021
38a3ddd
Updating readme
winglam Mar 3, 2021
1c1835e
Merging
winglam Mar 3, 2021
c6cfb24
Merging
winglam Mar 5, 2021
28f53b5
Cleaning up unnecessary changes.
winglam Mar 5, 2021
a0f050e
Removing surefire changing extension
winglam Mar 5, 2021
f29212d
Formatting issues.
winglam Mar 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ public class IntegrationTestMojo
@Parameter( property = "failsafe.runOrder", defaultValue = "filesystem" )
private String runOrder;

//TODO docs
@Parameter( property = "failsafe.methodRunOrder", defaultValue = "default" )
private String methodRunOrder;

/**
* Sets the random seed that will be used to order the tests if {@code failsafe.runOrder} is set to {@code random}.
* <br>
Expand Down Expand Up @@ -907,6 +911,12 @@ public void setRunOrder( String runOrder )
this.runOrder = runOrder;
}

@Override
public String getMethodRunOrder()
{
return methodRunOrder;
}

@Override
public Long getRunOrderRandomSeed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.apache.maven.surefire.api.testset.TestSetFailedException;
import org.apache.maven.surefire.api.util.DefaultScanResult;
import org.apache.maven.surefire.api.util.RunOrder;
import org.apache.maven.surefire.util.MethodRunOrder;
import org.apache.maven.toolchain.DefaultToolchain;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
Expand Down Expand Up @@ -679,7 +680,7 @@ public abstract class AbstractSurefireMojo
*
* @since 2.2
*/
@Parameter( property = "trimStackTrace", defaultValue = "true" )
@Parameter( property = "trimStackTrace", defaultValue = "false" )
private boolean trimStackTrace;

/**
Expand Down Expand Up @@ -865,6 +866,8 @@ public abstract class AbstractSurefireMojo

public abstract void setRunOrder( String runOrder );

public abstract String getMethodRunOrder();

public abstract Long getRunOrderRandomSeed();

public abstract void setRunOrderRandomSeed( Long runOrderRandomSeed );
Expand Down Expand Up @@ -1291,7 +1294,8 @@ private RunResult executeProvider( @Nonnull ProviderInfo provider, @Nonnull Defa
ClassLoaderConfiguration classLoaderConfiguration = getClassLoaderConfiguration();
provider.addProviderProperties();
RunOrderParameters runOrderParameters =
new RunOrderParameters( getRunOrder(), getStatisticsFile( getConfigChecksum() ), getRunOrderRandomSeed() );
new RunOrderParameters( getRunOrder(), getStatisticsFile( getConfigChecksum() ), getRunOrderRandomSeed(),
getMethodRunOrder() );

if ( isNotForking() )
{
Expand Down Expand Up @@ -2754,6 +2758,7 @@ private String getConfigChecksum()
checksum.add( getObjectFactory() );
checksum.add( getFailIfNoTests() );
checksum.add( getRunOrder() );
checksum.add( getMethodRunOrder().toString() );
checksum.add( getDependenciesToScan() );
checksum.add( getForkedProcessExitTimeoutInSeconds() );
checksum.add( getRerunFailingTestsCount() );
Expand Down Expand Up @@ -3068,7 +3073,9 @@ protected void warnIfIllegalFailOnFlakeCount() throws MojoFailureException

private void printDefaultSeedIfNecessary()
{
if ( getRunOrderRandomSeed() == null && getRunOrder().equals( RunOrder.RANDOM.name() ) )
if ( getRunOrderRandomSeed() == null
&& ( getRunOrder().equals( RunOrder.RANDOM.name() )
|| getMethodRunOrder().equals( MethodRunOrder.RANDOM.name() ) ) )
{
setRunOrderRandomSeed( System.nanoTime() );
getConsoleLogger().info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static org.apache.maven.surefire.booter.BooterConstants.INCLUDES_PROPERTY_PREFIX;
import static org.apache.maven.surefire.booter.BooterConstants.ISTRIMSTACKTRACE;
import static org.apache.maven.surefire.booter.BooterConstants.MAIN_CLI_OPTIONS;
import static org.apache.maven.surefire.booter.BooterConstants.METHOD_RUN_ORDER;
import static org.apache.maven.surefire.booter.BooterConstants.PLUGIN_PID;
import static org.apache.maven.surefire.booter.BooterConstants.PROCESS_CHECKER;
import static org.apache.maven.surefire.booter.BooterConstants.PROVIDER_CONFIGURATION;
Expand Down Expand Up @@ -163,6 +164,7 @@ File serialize( KeyValueSource sourceProperties, ProviderConfiguration providerC
{
properties.setProperty( RUN_ORDER, RunOrder.asString( runOrderParameters.getRunOrder() ) );
properties.setProperty( RUN_STATISTICS_FILE, runOrderParameters.getRunStatisticsFile() );
properties.setProperty( METHOD_RUN_ORDER, runOrderParameters.getMethodRunOrder().toString() );
properties.setProperty( RUN_ORDER_RANDOM_SEED, runOrderParameters.getRunOrderRandomSeed() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,12 @@ public void setRunOrder( String runOrder )

}

@Override
public String getMethodRunOrder()
{
return null;
};

@Override
public Long getRunOrderRandomSeed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,12 @@ public void setRunOrder( String runOrder )

}

@Override
public String getMethodRunOrder()
{
return null;
};

@Override
public Long getRunOrderRandomSeed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,12 @@ public void setRunOrder( String runOrder )

}

@Override
public String getMethodRunOrder()
{
return null;
};

@Override
public Long getRunOrderRandomSeed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.maven.surefire.api.testset.TestListResolver;
import org.apache.maven.surefire.api.testset.TestRequest;
import org.apache.maven.surefire.api.util.RunOrder;
import org.apache.maven.surefire.util.MethodRunOrder;
import org.junit.After;
import org.junit.Before;

Expand Down Expand Up @@ -276,7 +277,8 @@ private ProviderConfiguration getTestProviderConfiguration( DirectoryScannerPara
new TestRequest( getSuiteXmlFileStrings(), getTestSourceDirectory(),
new TestListResolver( USER_REQUESTED_TEST + "#aUserRequestedTestMethod" ),
RERUN_FAILING_TEST_COUNT );
RunOrderParameters runOrderParameters = new RunOrderParameters( RunOrder.DEFAULT, null );
RunOrderParameters runOrderParameters = new RunOrderParameters( RunOrder.DEFAULT, null, null,
MethodRunOrder.DEFAULT );
return new ProviderConfiguration( directoryScannerParameters, runOrderParameters, true, reporterConfiguration,
new TestArtifactInfo( "5.0", "ABC" ), testSuiteDefinition, new HashMap<String, String>(), TEST_TYPED,
readTestsFromInStream, cli, 0, Shutdown.DEFAULT, 0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.maven.surefire.api.testset.TestListResolver;
import org.apache.maven.surefire.api.testset.TestRequest;
import org.apache.maven.surefire.api.util.RunOrder;
import org.apache.maven.surefire.util.MethodRunOrder;
import org.junit.After;
import org.junit.Before;

Expand Down Expand Up @@ -197,7 +198,8 @@ private ProviderConfiguration getProviderConfiguration()
new TestRequest( Arrays.asList( getSuiteXmlFileStrings() ), getTestSourceDirectory(),
new TestListResolver( "aUserRequestedTest#aUserRequestedTestMethod" ) );

RunOrderParameters runOrderParameters = new RunOrderParameters( RunOrder.DEFAULT, null );
RunOrderParameters runOrderParameters = new RunOrderParameters( RunOrder.DEFAULT, null, null,
MethodRunOrder.DEFAULT );
return new ProviderConfiguration( directoryScannerParameters, runOrderParameters, true, reporterConfiguration,
new TestArtifactInfo( "5.0", "ABC" ), testSuiteDefinition, new HashMap<String, String>(),
BooterDeserializerProviderConfigurationTest.TEST_TYPED, true, cli, 0, Shutdown.DEFAULT, 0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -302,6 +305,10 @@ public class SurefirePlugin
@Parameter( property = "surefire.runOrder", defaultValue = "filesystem" )
private String runOrder;

//TODO docs
@Parameter( property = "surefire.methodRunOrder", defaultValue = "default" )
private String methodRunOrder;

/**
* Sets the random seed that will be used to order the tests if {@code surefire.runOrder} is set to {@code random}.
* <br>
Expand Down Expand Up @@ -629,6 +636,24 @@ public void setReportsDirectory( File reportsDirectory )
@Override
public String getTest()
{
File f = new File( test );
if ( f.exists() && !f.isDirectory ( ) )
{
try
{
List<String> l = Files.readAllLines( f.toPath(), Charset.defaultCharset( ) );
StringBuilder sb = new StringBuilder( );
for ( String s : l )
{
sb.append( s + "," );
}
String s = sb.toString( );
return s.substring( 0 , s.length( ) - 1 );
}
catch ( IOException e )
{
}
}
return test;
}

Expand Down Expand Up @@ -832,6 +857,13 @@ public void setRunOrder( String runOrder )
this.runOrder = runOrder;
}


@Override
public String getMethodRunOrder()
{
return methodRunOrder;
}

@Override
public Long getRunOrderRandomSeed()
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.17</version>
<version>1.18</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.File;
import org.apache.maven.surefire.api.util.RunOrder;
import org.apache.maven.surefire.util.MethodRunOrder;

/**
* @author Kristian Rosenvold
Expand All @@ -31,39 +32,70 @@ public class RunOrderParameters

private File runStatisticsFile;

private final MethodRunOrder methodRunOrder;

private Long runOrderRandomSeed;

public RunOrderParameters( RunOrder[] runOrder, File runStatisticsFile )
public RunOrderParameters( RunOrder[] runOrder, File runStatisticsFile, MethodRunOrder methodRunOrder )
{
this.runOrder = runOrder;
this.runStatisticsFile = runStatisticsFile;
this.methodRunOrder = methodRunOrder;
this.runOrderRandomSeed = null;
}

public RunOrderParameters( String runOrder, File runStatisticsFile )
public RunOrderParameters( RunOrder[] runOrder, File runStatisticsFile, Long runOrderRandomSeed,
MethodRunOrder methodRunOrder )
{
this.runOrder = runOrder;
this.runStatisticsFile = runStatisticsFile;
this.methodRunOrder = methodRunOrder;
this.runOrderRandomSeed = runOrderRandomSeed;
}

public RunOrderParameters( String runOrder, File runStatisticsFile, Long runOrderRandomSeed, String methodRunOrder )
{
this.runOrder = runOrder == null ? RunOrder.DEFAULT : RunOrder.valueOfMulti( runOrder );
this.runStatisticsFile = runStatisticsFile;
this.runOrderRandomSeed = null;
this.methodRunOrder = MethodRunOrder.valueOf( methodRunOrder );
this.runOrderRandomSeed = runOrderRandomSeed;
}

public RunOrderParameters( RunOrder[] runOrder, File runStatisticsFile, Long runOrderRandomSeed )
{
this.runOrder = runOrder;
this.runStatisticsFile = runStatisticsFile;
this.runOrderRandomSeed = runOrderRandomSeed;
this.methodRunOrder = MethodRunOrder.DEFAULT;
}

public RunOrderParameters( String runOrder, File runStatisticsFile, Long runOrderRandomSeed )
{
this.runOrder = runOrder == null ? RunOrder.DEFAULT : RunOrder.valueOfMulti( runOrder );
this.runStatisticsFile = runStatisticsFile;
this.runOrderRandomSeed = runOrderRandomSeed;
this.methodRunOrder = MethodRunOrder.DEFAULT;
}

public RunOrderParameters( RunOrder[] runOrder, File runStatisticsFile )
{
this.runOrder = runOrder;
this.runStatisticsFile = runStatisticsFile;
this.runOrderRandomSeed = null;
this.methodRunOrder = MethodRunOrder.DEFAULT;
}

public RunOrderParameters( String runOrder, File runStatisticsFile )
{
this.runOrder = runOrder == null ? RunOrder.DEFAULT : RunOrder.valueOfMulti( runOrder );
this.runStatisticsFile = runStatisticsFile;
this.runOrderRandomSeed = null;
this.methodRunOrder = MethodRunOrder.DEFAULT;
}

public static RunOrderParameters alphabetical()
{
return new RunOrderParameters( new RunOrder[]{ RunOrder.ALPHABETICAL }, null );
return new RunOrderParameters( new RunOrder[]{ RunOrder.ALPHABETICAL }, null, null, MethodRunOrder.DEFAULT );
}

public RunOrder[] getRunOrder()
Expand All @@ -86,4 +118,9 @@ public File getRunStatisticsFile()
return runStatisticsFile;
}

public MethodRunOrder getMethodRunOrder()
{
return methodRunOrder;
}

}
Loading