From 088fad6f0c4abe529765e8c495b26e945c8f9183 Mon Sep 17 00:00:00 2001 From: tibordigana Date: Sun, 20 Mar 2022 23:01:45 +0100 Subject: [PATCH] [SUREFIRE-2040] No tests executed with junit-platform-suite and -Dtest=TestSuite --- .../site/apt/examples/junit-platform.apt.vm | 37 ++++++++ .../its/jiras/Surefire1787JUnit5IT.java | 16 ++++ .../src/test/resources/junit5-suite/pom.xml | 94 +++++++++++++++++++ .../src/test/java/pkg/JUnit5Tests.java | 29 ++++++ .../src/test/java/pkg/domain/AxTest.java | 30 ++++++ .../src/test/java/pkg/domain/BxTest.java | 33 +++++++ .../junitplatform/JUnitPlatformProvider.java | 7 +- 7 files changed, 243 insertions(+), 3 deletions(-) create mode 100644 surefire-its/src/test/resources/junit5-suite/pom.xml create mode 100644 surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/JUnit5Tests.java create mode 100644 surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/domain/AxTest.java create mode 100644 surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/domain/BxTest.java 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 e1426a680a..5c02c6d1c8 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 @@ -294,6 +294,7 @@ Using JUnit 5 Platform org.apache.maven.plugins maven-surefire-plugin + ${project.version} org.junit.jupiter @@ -334,6 +335,7 @@ Using JUnit 5 Platform org.apache.maven.plugins maven-surefire-plugin + ${project.version} org.junit.vintage @@ -411,6 +413,41 @@ Using JUnit 5 Platform +---+ +** JUnit5 Suite + + For more information see this + {{{https://github.com/apache/maven-surefire/tree/master/surefire-its/src/test/resources/junit5-suite}example with surefire integration test}} + and the {{{https://junit.org/junit5/docs/current/user-guide/#junit-platform-suite-engine}tutorial}}. + ++---+ + + + org.junit.jupiter + junit-jupiter-engine + 5.8.2 + test + + + org.junit.platform + junit-platform-suite-engine + 1.8.2 + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${project.version} + + + + + + ++---+ + * Provider Selection If nothing is configured, Surefire detects which JUnit version to use by the following algorithm: diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java index 3e7e056b53..f64ad702bd 100644 --- a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java @@ -22,6 +22,9 @@ import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.junit.Test; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; + /** * */ @@ -129,4 +132,17 @@ public void junit4Runner() .verifyTextInLog( "Running pkg.JUnit5Tests" ) .verifyTextInLog( "Using auto detected provider org.apache.maven.surefire.junit4.JUnit4Provider" ); } + + @Test + public void junit5Suite() throws Exception + { + unpack( "junit5-suite" ) + .executeTest() + .verifyErrorFree( 1 ) + .verifyTextInLog( + "Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" ) + .verifyTextInLog( "Running pkg.JUnit5Test" ) + .verifyTextInLog( "Running pkg.domain.AxTest" ) + .assertThatLogLine( containsString( "Running pkg.domain.BxTest" ), equalTo( 0 ) ); + } } diff --git a/surefire-its/src/test/resources/junit5-suite/pom.xml b/surefire-its/src/test/resources/junit5-suite/pom.xml new file mode 100644 index 0000000000..7ad8611282 --- /dev/null +++ b/surefire-its/src/test/resources/junit5-suite/pom.xml @@ -0,0 +1,94 @@ + + + + + 4.0.0 + + org.example + junit5-suite + 1.0-SNAPSHOT + + + UTF-8 + ${java.specification.version} + ${java.specification.version} + + + + + org.junit.jupiter + junit-jupiter-api + + 5.7.2 + test + + + org.junit.platform + junit-platform-suite-api + + 1.7.2 + test + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + JUnit5Tests + + + + + org.junit.jupiter + junit-jupiter-engine + 5.8.2 + + + org.junit.platform + junit-platform-suite-engine + 1.8.2 + + + + + + + + diff --git a/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/JUnit5Tests.java b/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/JUnit5Tests.java new file mode 100644 index 0000000000..a9cb8d63f6 --- /dev/null +++ b/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/JUnit5Tests.java @@ -0,0 +1,29 @@ +package pkg; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; + +@Suite +@SelectClasses({pkg.domain.AxTest.class}) +public class JUnit5Tests +{ +} diff --git a/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/domain/AxTest.java b/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/domain/AxTest.java new file mode 100644 index 0000000000..ca7c26c807 --- /dev/null +++ b/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/domain/AxTest.java @@ -0,0 +1,30 @@ +package pkg.domain; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.jupiter.api.Test; + +public class AxTest +{ + @Test + void test() + { + } +} diff --git a/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/domain/BxTest.java b/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/domain/BxTest.java new file mode 100644 index 0000000000..767ec07d6d --- /dev/null +++ b/surefire-its/src/test/resources/junit5-suite/src/test/java/pkg/domain/BxTest.java @@ -0,0 +1,33 @@ +package pkg.domain; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + +public class BxTest +{ + @Test + void test() + { + fail(); + } +} 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 92385e5fcd..efcf719efd 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 @@ -32,6 +32,7 @@ import static org.apache.maven.surefire.api.report.ConsoleOutputCapture.startCapture; import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN; import static org.apache.maven.surefire.api.report.RunMode.RERUN_TEST_AFTER_FAILURE; +import static org.apache.maven.surefire.api.testset.TestListResolver.optionallyWildcardFilter; import static org.apache.maven.surefire.api.util.TestsToRun.fromClass; import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; @@ -275,10 +276,10 @@ private Filter[] newFilters() .map( TagFilter::excludeTags ) .ifPresent( filters::add ); - TestListResolver testListResolver = parameters.getTestRequest().getTestListResolver(); - if ( !testListResolver.isEmpty() ) + TestListResolver filter = optionallyWildcardFilter( parameters.getTestRequest().getTestListResolver() ); + if ( !filter.isEmpty() && !filter.isWildcard() ) { - filters.add( new TestMethodFilter( testListResolver ) ); + filters.add( new TestMethodFilter( filter ) ); } getPropertiesList( INCLUDE_JUNIT5_ENGINES_PROP )