From af074c200dd0ed71502830b3fbdfe55c4315221f Mon Sep 17 00:00:00 2001 From: Rui Zhang Date: Fri, 15 Oct 2021 11:55:24 -0500 Subject: [PATCH 1/2] Fixing issue in extension that would not allow files being used for test order --- README.md | 2 +- .../api/util/DefaultRunOrderCalculator.java | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 90ce427b90..7a991594fb 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Specifically, running the command above will result in the tests running in the ## Example with file ``` -mvn test -Dtest=path_to_file -Dsurefire.runOrder=testorder -pl dubbo-rpc/dubbo-rpc-dubbo +mvn test -Dsurefire.includesFile=path_to_file -Dsurefire.runOrder=testorder -pl dubbo-rpc/dubbo-rpc-dubbo ``` By specifying ```-Dsurefire.runOrder=testorder``` Maven test will run the specifed tests in the order that they appear in the file ```path_to_file```. Note that the ```path_to_file``` should be an **absolute** path (e.g., ```/home/user/project/test-list```). diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DefaultRunOrderCalculator.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DefaultRunOrderCalculator.java index 6a06a99b8d..53e3cbf8e1 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DefaultRunOrderCalculator.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DefaultRunOrderCalculator.java @@ -23,6 +23,10 @@ import org.apache.maven.surefire.api.testset.RunOrderParameters; import org.apache.maven.surefire.api.testset.TestListResolver; +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -120,10 +124,24 @@ public int compare( String o1, String o2 ) public TestListResolver getTestListResolver() { String orderParam = System.getProperty( "test" ); - if ( orderParam == null ) + if ( orderParam == null ) { - throw new IllegalStateException( "TestListResolver in RunOrderCalculator should be used only when " - + "system property -Dtest is set and runOrder is testorder" ); + String orderParamFile = System.getProperty( "surefire.includesFile" ); + if ( orderParamFile == null ) + { + throw new IllegalStateException( "TestListResolver in RunOrderCalculator should be used only when " + + "system property -Dtest or -Dsurefire.includesFile is set and runOrder is testorder" ); + } + try + { + return new TestListResolver( + Files.readAllLines( new File( System.getProperty( "surefire.includesFile" ) ) + .toPath(), Charset.defaultCharset() ) ); + } + catch ( IOException e ) + { + e.printStackTrace(); + } } return new TestListResolver( Arrays.asList( orderParam.split( "," ) ) ); } From e49a8841b55dad694a0fa7a6c0b4ba2630842ec1 Mon Sep 17 00:00:00 2001 From: Rui Zhang <39625781+RayZhang001@users.noreply.github.com> Date: Tue, 19 Oct 2021 02:55:30 -0500 Subject: [PATCH 2/2] Fixing issue in extension that would not allow files being used for test order --- .../plugin/surefire/AbstractSurefireMojo.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index 18cfa72bde..105732a9bf 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -103,6 +103,7 @@ import java.io.IOException; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.nio.charset.Charset; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; @@ -2265,7 +2266,24 @@ private List getIncludeList() if ( isSpecificTestSpecified() ) { includes = new ArrayList<>(); - addAll( includes, split( getTest(), "," ) ); + + File file = new File( getTest() ); + + if ( file.exists() ) + { + try + { + includes = Files.readAllLines( file.toPath( ), Charset.defaultCharset( ) ); + } + catch ( IOException e ) + { + e.printStackTrace(); + } + } + else + { + addAll( includes, split( getTest(), "," ) ); + } } else {