[maven-surefire] branch master updated: [SUREFIRE-1854] Support include/exclude junit test engine

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[maven-surefire] branch master updated: [SUREFIRE-1854] Support include/exclude junit test engine

Tibor Digana
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new ee13f5d  [SUREFIRE-1854] Support include/exclude junit test engine
ee13f5d is described below

commit ee13f5d114a4236d6ab87878456cb438989b15fa
Author: adam11grafik <[hidden email]>
AuthorDate: Thu Apr 1 10:38:06 2021 +0200

    [SUREFIRE-1854] Support include/exclude junit test engine
---
 .../maven/plugin/failsafe/IntegrationTestMojo.java | 38 +++++++++++
 .../plugin/failsafe/IntegrationTestMojoTest.java   | 10 +++
 .../plugin/surefire/AbstractSurefireMojo.java      | 35 ++++++++++
 .../surefire/SurefireExecutionParameters.java      |  9 +++
 .../AbstractSurefireMojoJava7PlusTest.java         | 45 ++++++++++++
 .../plugin/surefire/AbstractSurefireMojoTest.java  | 52 ++++++++++++++
 .../maven/plugin/surefire/MojoMocklessTest.java    | 24 +++++++
 .../maven/plugin/surefire/SurefirePlugin.java      | 38 +++++++++++
 .../src/site/apt/examples/junit-platform.apt.vm    | 37 ++++++++++
 .../maven/plugin/surefire/SurefirePluginTest.java  | 11 +++
 .../api/booter/ProviderParameterNames.java         |  4 ++
 .../junitplatform/JUnitPlatformProvider.java       | 13 +++-
 .../junitplatform/JUnitPlatformProviderTest.java   | 79 +++++++++++++++++++++-
 13 files changed, 393 insertions(+), 2 deletions(-)

diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
index 2a207c8..a91139c 100644
--- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
+++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
@@ -476,6 +476,22 @@ public class IntegrationTestMojo
     @Parameter( property = "failsafe.systemPropertiesFile" )
     private File systemPropertiesFile;
 
+    /**
+     * Provide the ID/s of an JUnit engine to be included in the test run.
+     *
+     * @since 3.0.0-M6
+     */
+    @Parameter( property = "includeJUnit5Engines" )
+    private String[] includeJUnit5Engines;
+
+    /**
+     * Provide the ID/s of an JUnit engine to be excluded in the test run.
+     *
+     * @since 3.0.0-M6
+     */
+    @Parameter( property = "excludeJUnit5Engines" )
+    private String[] excludeJUnit5Engines;
+
     @Override
     protected int getRerunFailingTestsCount()
     {
@@ -977,4 +993,26 @@ public class IntegrationTestMojo
     {
         return enableProcessChecker;
     }
+
+    public String[] getIncludeJUnit5Engines()
+    {
+        return includeJUnit5Engines;
+    }
+
+    @SuppressWarnings( "UnusedDeclaration" )
+    public void setIncludeJUnit5Engines( String[] includeJUnit5Engines )
+    {
+        this.includeJUnit5Engines = includeJUnit5Engines;
+    }
+
+    public String[] getExcludeJUnit5Engines()
+    {
+        return excludeJUnit5Engines;
+    }
+
+    @SuppressWarnings( "UnusedDeclaration" )
+    public void setExcludeJUnit5Engines( String[] excludeJUnit5Engines )
+    {
+        this.excludeJUnit5Engines = excludeJUnit5Engines;
+    }
 }
diff --git a/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java b/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
index f5edf0b..63009f1 100644
--- a/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
+++ b/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
@@ -103,4 +103,14 @@ public class IntegrationTestMojoTest
         assertThat( mojo.getSystemPropertiesFile() )
                 .isEqualTo( new File( "testShouldGetPropertyFile" ) );
     }
+
+    @Test
+    public void shouldHaveJUnit5EnginesFilter()
+    {
+        mojo.setIncludeJUnit5Engines( new String[] { "e1", "e2" } );
+        assertThat( mojo.getIncludeJUnit5Engines() ).isEqualTo( new String[] { "e1", "e2" } );
+
+        mojo.setExcludeJUnit5Engines( new String[] { "e1", "e2" } );
+        assertThat( mojo.getExcludeJUnit5Engines() ).isEqualTo( new String[] { "e1", "e2" } );
+    }
 }
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 4d1af3d..18cfa72 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
@@ -150,6 +150,8 @@ import static org.apache.maven.surefire.api.suite.RunResult.failure;
 import static org.apache.maven.surefire.api.suite.RunResult.noTestsRun;
 import static org.apache.maven.surefire.api.util.ReflectionUtils.invokeMethodWithArray;
 import static org.apache.maven.surefire.api.util.ReflectionUtils.tryGetMethod;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.INCLUDE_JUNIT5_ENGINES_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.EXCLUDE_JUNIT5_ENGINES_PROP;
 
 /**
  * Abstract base class for running tests using Surefire.
@@ -1560,6 +1562,35 @@ public abstract class AbstractSurefireMojo
         }
     }
 
+    private void convertJunitEngineParameters()
+    {
+        if ( getIncludeJUnit5Engines() != null && getIncludeJUnit5Engines().length != 0 )
+        {
+            getProperties()
+                .setProperty( INCLUDE_JUNIT5_ENGINES_PROP, join( getIncludeJUnit5Engines() ) );
+        }
+
+        if ( getExcludeJUnit5Engines() != null && getExcludeJUnit5Engines().length != 0 )
+        {
+            getProperties()
+                .setProperty( EXCLUDE_JUNIT5_ENGINES_PROP, join( getExcludeJUnit5Engines() ) );
+        }
+    }
+
+    private static String join( String[] array )
+    {
+        StringBuilder stringBuilder = new StringBuilder();
+        for ( int i = 0, length = array.length; i < length; i++ )
+        {
+            stringBuilder.append( array[i] );
+            if ( i < length - 1 )
+            {
+                stringBuilder.append( ',' );
+            }
+        }
+        return stringBuilder.toString();
+    }
+
     protected boolean isAnyConcurrencySelected()
     {
         return getParallel() != null && !getParallel().trim().isEmpty();
@@ -2732,6 +2763,8 @@ public abstract class AbstractSurefireMojo
         checksum.add( isChildDelegation() );
         checksum.add( getGroups() );
         checksum.add( getExcludedGroups() );
+        checksum.add( getIncludeJUnit5Engines() );
+        checksum.add( getExcludeJUnit5Engines() );
         checksum.add( getSuiteXmlFiles() );
         checksum.add( getJunitArtifact() );
         checksum.add( getTestNGArtifactName() );
@@ -3238,6 +3271,7 @@ public abstract class AbstractSurefireMojo
         public void addProviderProperties()
         {
             convertGroupParameters();
+            convertJunitEngineParameters();
         }
 
         @Nonnull
@@ -3416,6 +3450,7 @@ public abstract class AbstractSurefireMojo
         {
             convertJunitCoreParameters();
             convertGroupParameters();
+            convertJunitEngineParameters();
         }
 
         @Nonnull
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java
index e66a7dd..a570b82 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireExecutionParameters.java
@@ -21,6 +21,7 @@ package org.apache.maven.plugin.surefire;
 
 import java.io.File;
 import java.util.List;
+
 import org.apache.maven.artifact.repository.ArtifactRepository;
 
 /**
@@ -129,4 +130,12 @@ public interface SurefireExecutionParameters
     int getSkipAfterFailureCount();
 
     String getShutdown();
+
+    String[] getIncludeJUnit5Engines();
+
+    void setIncludeJUnit5Engines( String[] includeJUnit5Engines );
+
+    String[] getExcludeJUnit5Engines();
+
+    void setExcludeJUnit5Engines( String[] excludeJUnit5Engines );
 }
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
index c9dbf5c..f8a4c10 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJava7PlusTest.java
@@ -466,6 +466,27 @@ public class AbstractSurefireMojoJava7PlusTest
             "--add-opens", "org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED"}, atIndex( 1 ) );
     }
 
+    @Test
+    public void shouldJoinStrings() throws Exception
+    {
+        Class<?>[] methodArgTypes = {String[].class};
+
+        Object[] args = { new String[]{"my-engine"} };
+        String result = invokeMethod( AbstractSurefireMojo.class, "join", methodArgTypes, args );
+        assertThat( result ).isNotNull();
+        assertThat( result ).isEqualTo( "my-engine" );
+
+        args = new Object[]{ new String[]{"my-engine1", "my-engine2"} };
+        result = invokeMethod( AbstractSurefireMojo.class, "join", methodArgTypes, args );
+        assertThat( result ).isNotNull();
+        assertThat( result ).isEqualTo( "my-engine1,my-engine2" );
+
+        args = new Object[]{new String[0]};
+        result = invokeMethod( AbstractSurefireMojo.class, "join", methodArgTypes, args );
+        assertThat( result ).isNotNull();
+        assertThat( result ).isEmpty();
+    }
+
     private static File mockFile( String absolutePath )
     {
         File f = mock( File.class );
@@ -916,5 +937,29 @@ public class AbstractSurefireMojoJava7PlusTest
         {
 
         }
+
+        @Override
+        public String[] getIncludeJUnit5Engines()
+        {
+            return null;
+        }
+
+        @Override
+        public void setIncludeJUnit5Engines( String[] includeJUnit5Engines )
+        {
+
+        }
+
+        @Override
+        public String[] getExcludeJUnit5Engines()
+        {
+            return null;
+        }
+
+        @Override
+        public void setExcludeJUnit5Engines( String[] excludeJUnit5Engines )
+        {
+
+        }
     }
 }
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
index 53e7fba..45e35b7 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
@@ -84,6 +84,7 @@ import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import static java.io.File.separatorChar;
@@ -1891,6 +1892,31 @@ public class AbstractSurefireMojoTest
                         entry( "org.opentest4j:opentest4j", testClasspathOpentest4j ) );
     }
 
+    @Test
+    public void shouldConvertJunitEngineParameters() throws Exception
+    {
+        Properties properties = new Properties();
+        setInternalState( mojo, "properties", properties );
+
+        invokeMethod( mojo, "convertJunitEngineParameters" );
+        assertThat( properties ).isEmpty();
+
+        mojo.setIncludeJUnit5Engines( new String[0] );
+        mojo.setExcludeJUnit5Engines( new String[0] );
+        invokeMethod( mojo, "convertJunitEngineParameters" );
+        assertThat( properties ).isEmpty();
+
+        mojo.setIncludeJUnit5Engines( new String[] { "e1", "e2" } );
+        invokeMethod( mojo, "convertJunitEngineParameters" );
+        assertThat( properties )
+            .includes( entry( "includejunit5engines", "e1,e2" ) );
+
+        mojo.setExcludeJUnit5Engines( new String[] { "e1", "e2" } );
+        invokeMethod( mojo, "convertJunitEngineParameters" );
+        assertThat( properties )
+            .includes( entry( "excludejunit5engines", "e1,e2" ) );
+    }
+
     private static ArtifactResolutionResult createJUnitPlatformLauncherResolutionResult(
             Artifact junit5Engine, Artifact apiguardian, Artifact commons, Artifact opentest4j )
     {
@@ -2027,6 +2053,8 @@ public class AbstractSurefireMojoTest
         private File testClassesDirectory;
         private boolean useModulePath;
         private int failOnFlakeCount;
+        private String[] includeJUnit5Engines;
+        private String[] excludeJUnit5Engines;
 
         private JUnitPlatformProviderInfo createJUnitPlatformProviderInfo( Artifact junitPlatformArtifact,
                                                                            TestClassPath testClasspathWrapper )
@@ -2482,6 +2510,30 @@ public class AbstractSurefireMojoTest
         {
             this.failOnFlakeCount = failOnFlakeCount;
         }
+
+        @Override
+        public String[] getIncludeJUnit5Engines()
+        {
+            return includeJUnit5Engines;
+        }
+
+        @Override
+        public void setIncludeJUnit5Engines( String[] includeJUnit5Engines )
+        {
+            this.includeJUnit5Engines = includeJUnit5Engines;
+        }
+
+        @Override
+        public String[] getExcludeJUnit5Engines()
+        {
+            return excludeJUnit5Engines;
+        }
+
+        @Override
+        public void setExcludeJUnit5Engines( String[] excludeJUnit5Engines )
+        {
+            this.excludeJUnit5Engines = excludeJUnit5Engines;
+        }
     }
 
     private static File mockFile( String absolutePath )
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
index 1c9b89f..fe7a44a 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
@@ -798,5 +798,29 @@ public class MojoMocklessTest
         {
 
         }
+
+        @Override
+        public String[] getIncludeJUnit5Engines()
+        {
+            return null;
+        }
+
+        @Override
+        public void setIncludeJUnit5Engines( String[] includeJUnit5Engines )
+        {
+
+        }
+
+        @Override
+        public String[] getExcludeJUnit5Engines()
+        {
+            return null;
+        }
+
+        @Override
+        public void setExcludeJUnit5Engines( String[] excludeJUnit5Engines )
+        {
+
+        }
     }
 }
diff --git a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
index 16ffaf9..5f48cad 100644
--- a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
+++ b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
@@ -466,6 +466,22 @@ public class SurefirePlugin
     @Parameter( property = "surefire.systemPropertiesFile" )
     private File systemPropertiesFile;
 
+    /**
+     * Provide the ID/s of an JUnit engine to be included in the test run.
+     *
+     * @since 3.0.0-M6
+     */
+    @Parameter( property = "includeJUnit5Engines" )
+    private String[] includeJUnit5Engines;
+
+    /**
+     * Provide the ID/s of an JUnit engine to be excluded in the test run.
+     *
+     * @since 3.0.0-M6
+     */
+    @Parameter( property = "excludeJUnit5Engines" )
+    private String[] excludeJUnit5Engines;
+
     @Override
     protected int getRerunFailingTestsCount()
     {
@@ -921,4 +937,26 @@ public class SurefirePlugin
     {
         checksum.add( skipAfterFailureCount );
     }
+
+    public String[] getIncludeJUnit5Engines()
+    {
+        return includeJUnit5Engines;
+    }
+
+    @SuppressWarnings( "UnusedDeclaration" )
+    public void setIncludeJUnit5Engines( String[] includeJUnit5Engines )
+    {
+        this.includeJUnit5Engines = includeJUnit5Engines;
+    }
+
+    public String[] getExcludeJUnit5Engines()
+    {
+        return excludeJUnit5Engines;
+    }
+
+    @SuppressWarnings( "UnusedDeclaration" )
+    public void setExcludeJUnit5Engines( String[] excludeJUnit5Engines )
+    {
+        this.excludeJUnit5Engines = excludeJUnit5Engines;
+    }
 }
diff --git a/maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm b/maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
index 44159de..e1426a6 100644
--- a/maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
+++ b/maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
@@ -518,6 +518,43 @@ else
 +---+
 
 
+* Filtering JUnit5 Engines
+
+   You can filter engines by the ID/s of an engine to be included or excluded in the test run.
+
+    * To include <<<engines>>>, use <<<includeJUnit5Engines>>>.
+
+    * To exclude <<<engines>>>, use <<<excludeJUnit5Engines>>>.
+
+   Be aware that this feature reserves system properties <<<includejunit5engines>>> and <<<excludejunit5engines>>>
+   for internal usage.
+
++---+
+...
+<build>
+    <plugins>
+        ...
+        <plugin>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>${project.artifactId}</artifactId>
+            <version>${project.version}</version>
+            <configuration>
+                <includeJUnit5Engines>
+                    <engine>my-first-engine-id-to-include</engine>
+                    <engine>my-second-engine-id-to-include</engine>
+                </includeJUnit5Engines>
+                <excludeJUnit5Engines>
+                    <engine>my-first-engine-id-to-include</engine>
+                    <engine>my-second-engine-id-to-include</engine>
+                </excludeJUnit5Engines>
+            </configuration>
+        </plugin>
+    </plugins>
+</build>
+...
++---+
+
+
 * Configuration Parameters
 
    You can set JUnit Platform configuration parameters to influence test discovery and execution by
diff --git a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
index 2da402a..72fd630 100644
--- a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
+++ b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
@@ -135,4 +135,15 @@ public class SurefirePluginTest extends TestCase
         e.expect( MojoFailureException.class );
         e.expectMessage( "\"failOnFlakeCount\" requires rerunFailingTestsCount to be at least 1." );
     }
+
+    public void testShouldHaveJUnit5EnginesFilter()
+    {
+        SurefirePlugin plugin = new SurefirePlugin();
+
+        plugin.setIncludeJUnit5Engines( new String[] { "e1", "e2" } );
+        assertThat( plugin.getIncludeJUnit5Engines() ).isEqualTo( new String[] { "e1", "e2" } );
+
+        plugin.setExcludeJUnit5Engines( new String[] { "e1", "e2" } );
+        assertThat( plugin.getExcludeJUnit5Engines() ).isEqualTo( new String[] { "e1", "e2" } );
+    }
 }
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/booter/ProviderParameterNames.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/booter/ProviderParameterNames.java
index 9f227b8..d4ae91e 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/api/booter/ProviderParameterNames.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/booter/ProviderParameterNames.java
@@ -28,6 +28,10 @@ public class ProviderParameterNames
 
     public static final String TESTNG_GROUPS_PROP = "groups";
 
+    public static final String INCLUDE_JUNIT5_ENGINES_PROP = "includejunit5engines";
+
+    public static final String EXCLUDE_JUNIT5_ENGINES_PROP = "excludejunit5engines";
+
     public static final String THREADCOUNT_PROP = "threadcount";
 
     public static final String PARALLEL_PROP = "parallel";
diff --git a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java
index 6853a3e..c8df55b 100644
--- a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java
+++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java
@@ -25,8 +25,10 @@ import static java.util.Optional.empty;
 import static java.util.Optional.of;
 import static java.util.logging.Level.WARNING;
 import static java.util.stream.Collectors.toList;
-import static org.apache.maven.surefire.api.booter.ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP;
 import static org.apache.maven.surefire.api.booter.ProviderParameterNames.TESTNG_GROUPS_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.INCLUDE_JUNIT5_ENGINES_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.EXCLUDE_JUNIT5_ENGINES_PROP;
 import static org.apache.maven.surefire.api.report.ConsoleOutputCapture.startCapture;
 import static org.apache.maven.surefire.api.util.TestsToRun.fromClass;
 import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank;
@@ -60,6 +62,7 @@ import org.apache.maven.surefire.api.util.TestsToRun;
 import org.apache.maven.surefire.shared.utils.StringUtils;
 import org.junit.platform.engine.DiscoverySelector;
 import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.EngineFilter;
 import org.junit.platform.launcher.Launcher;
 import org.junit.platform.launcher.LauncherDiscoveryRequest;
 import org.junit.platform.launcher.TagFilter;
@@ -230,6 +233,14 @@ public class JUnitPlatformProvider
             filters.add( new TestMethodFilter( testListResolver ) );
         }
 
+        getPropertiesList( INCLUDE_JUNIT5_ENGINES_PROP )
+            .map( EngineFilter::includeEngines )
+            .ifPresent( filters::add );
+
+        getPropertiesList( EXCLUDE_JUNIT5_ENGINES_PROP )
+            .map( EngineFilter::excludeEngines )
+            .ifPresent( filters::add );
+
         return filters.toArray( new Filter<?>[ filters.size() ] );
     }
 
diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTest.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTest.java
index 5064285..6d1ebf7 100644
--- a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTest.java
+++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTest.java
@@ -22,8 +22,10 @@ package org.apache.maven.surefire.junitplatform;
 import static java.util.Collections.emptyMap;
 import static java.util.Collections.singletonMap;
 import static java.util.stream.Collectors.toSet;
-import static org.apache.maven.surefire.api.booter.ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP;
 import static org.apache.maven.surefire.api.booter.ProviderParameterNames.TESTNG_GROUPS_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.INCLUDE_JUNIT5_ENGINES_PROP;
+import static org.apache.maven.surefire.api.booter.ProviderParameterNames.EXCLUDE_JUNIT5_ENGINES_PROP;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -70,6 +72,7 @@ import org.junit.Test;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.DisplayName;
+import org.junit.platform.launcher.EngineFilter;
 import org.junit.platform.launcher.Launcher;
 import org.junit.platform.launcher.TestIdentifier;
 import org.junit.platform.launcher.TestPlan;
@@ -767,6 +770,80 @@ public class JUnitPlatformProviderTest
     }
 
     @Test
+    public void onlyIncludeJunit5EnginesIsDeclared()
+    {
+        Map<String, String> properties = singletonMap( INCLUDE_JUNIT5_ENGINES_PROP, "engine-one, engine-two" );
+
+        ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+        when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+        JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+        assertThat( provider.getFilters() ).hasSize( 1 );
+        assertThat( provider.getFilters()[0] ).isInstanceOf( EngineFilter.class );
+    }
+
+    @Test
+    public void onlyExcludeJunit5EnginesIsDeclared()
+    {
+        Map<String, String> properties = singletonMap( EXCLUDE_JUNIT5_ENGINES_PROP, "engine-one, engine-two" );
+
+        ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+        when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+        JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+        assertThat( provider.getFilters() ).hasSize( 1 );
+        assertThat( provider.getFilters()[0] ).isInstanceOf( EngineFilter.class );
+    }
+
+    @Test
+    public void noFiltersAreCreatedIfIncludeJunit5EnginesIsEmpty()
+    {
+        Map<String, String> properties = singletonMap( INCLUDE_JUNIT5_ENGINES_PROP, "" );
+
+        ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+        when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+        JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+        assertEquals( 0, provider.getFilters().length );
+
+        assertThat( provider.getFilters() ).hasSize( 0 );
+    }
+
+    @Test
+    public void filtersWithEmptyJunitEngineAreNotRegistered()
+    {
+        // Here only tagOne is registered as a valid tag and other tags are ignored as they are empty
+        Map<String, String> properties = singletonMap( EXCLUDE_JUNIT5_ENGINES_PROP, "engine-one," );
+
+        ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+        when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+        JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+        assertThat( provider.getFilters() ).hasSize( 1 );
+        assertThat( provider.getFilters()[0] ).isInstanceOf( EngineFilter.class );
+    }
+
+    @Test
+    public void bothIncludeAndExcludeJunit5EnginesAreAllowed()
+    {
+        Map<String, String> properties = new HashMap<>();
+        properties.put( INCLUDE_JUNIT5_ENGINES_PROP, "engine-one, engine-two" );
+        properties.put( EXCLUDE_JUNIT5_ENGINES_PROP, "engine-three, engine-four" );
+
+        ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+        when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+        JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+        assertThat( provider.getFilters() ).hasSize( 2 );
+        assertThat( provider.getFilters()[0] ).isInstanceOf( EngineFilter.class );
+        assertThat( provider.getFilters()[1] ).isInstanceOf( EngineFilter.class );
+    }
+
+    @Test
     public void noFiltersAreCreatedIfNoPropertiesAreDeclared()
     {
         ProviderParameters providerParameters = providerParametersMock( TestClass1.class );