[SUREFIRE-1797] Surefire report with parameterized tests contain all names of test the same
diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformRerunFailingTestsIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformRerunFailingTestsIT.java
index 2a3bdca..1ae105f 100644
--- a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformRerunFailingTestsIT.java
+++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformRerunFailingTestsIT.java
@@ -203,6 +203,26 @@
verifyFailuresOneRetryOneMethod( outputValidator );
}
+ @Test
+ public void testParameterizedTest()
+ {
+ unpack()
+ .setJUnitVersion( VERSION )
+ .maven()
+ .activateProfile( "parameters" )
+ .withFailure()
+ .debugLogging()
+ .executeTest()
+ .assertTestSuiteResults( 6, 0, 1, 1, 0 )
+ .getSurefireReportsXmlFile( "TEST-junitplatform.ParametersTest.xml" )
+ .assertContainsText( "testOneFailingPassingTest(ConnectionPoolFactory)[1]" )
+ .assertContainsText( "testOneFailingPassingTest(ConnectionPoolFactory)[2]" )
+ .assertContainsText( "testOneFailingPassingTest(ConnectionPoolFactory)[3]" )
+ .assertContainsText( "testAllPassingTest(ConnectionPoolFactory)[1]" )
+ .assertContainsText( "testAllPassingTest(ConnectionPoolFactory)[2]" )
+ .assertContainsText( "testAllPassingTest(ConnectionPoolFactory)[3]" );
+ }
+
private void verifyFailuresOneRetryAllClasses( OutputValidator outputValidator )
{
verifyFailuresOneRetry( outputValidator, 5, 1, 1, 0 );
diff --git a/surefire-its/src/test/resources/junit-platform-rerun-failing-tests/pom.xml b/surefire-its/src/test/resources/junit-platform-rerun-failing-tests/pom.xml
index af4dde0..cea4be0 100644
--- a/surefire-its/src/test/resources/junit-platform-rerun-failing-tests/pom.xml
+++ b/surefire-its/src/test/resources/junit-platform-rerun-failing-tests/pom.xml
@@ -40,16 +40,54 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire.version}</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>${surefire.version}</version>
+ <configuration>
+ <excludes>
+ <exclude>**/ParametersTest.java</exclude>
+ </excludes>
+ </configuration>
</plugin>
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>parameters</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/PassingTest.java</exclude>
+ <exclude>**/FlakyFirstTimeTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/surefire-its/src/test/resources/junit-platform-rerun-failing-tests/src/test/java/junitplatform/ParametersTest.java b/surefire-its/src/test/resources/junit-platform-rerun-failing-tests/src/test/java/junitplatform/ParametersTest.java
new file mode 100644
index 0000000..a4e4e38
--- /dev/null
+++ b/surefire-its/src/test/resources/junit-platform-rerun-failing-tests/src/test/java/junitplatform/ParametersTest.java
@@ -0,0 +1,76 @@
+package junitplatform;
+
+/*
+ * 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 org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.stream.Stream;
+
+
+public class ParametersTest
+{
+ public static Stream<ConnectionPoolFactory> pools()
+ {
+ return Stream.of( new ConnectionPoolFactory( "duplex" ),
+ new ConnectionPoolFactory( "multiplex" ),
+ new ConnectionPoolFactory( "round-robin" ) );
+ }
+
+ @ParameterizedTest
+ @MethodSource( "pools" )
+ public void testAllPassingTest( ConnectionPoolFactory factory )
+ {
+ System.out.println( "testAllPassingTest factory " + factory );
+ }
+
+ @ParameterizedTest
+ @MethodSource( "pools" )
+ public void testOneFailingPassingTest( ConnectionPoolFactory factory ) throws Exception
+ {
+ Assumptions.assumeFalse( factory.name.equals( "round-robin" ) );
+ System.out.println( "Passing test factory " + factory );
+ if ( factory.name.equals( "multiplex" ) )
+ {
+ assertEquals( 1, 2 );
+ }
+ }
+
+ private static class ConnectionPoolFactory
+ {
+ private final String name;
+
+ private ConnectionPoolFactory( String name )
+ {
+ this.name = name;
+ }
+
+ @Override
+ public String toString()
+ {
+ return name;
+ }
+ }
+}
diff --git a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
index 31c010a..c0cfed2 100644
--- a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
+++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
@@ -22,6 +22,7 @@
import static java.util.Collections.emptyMap;
import static java.util.stream.Collectors.joining;
import static org.apache.maven.surefire.api.util.internal.ObjectUtils.systemProps;
+import static org.apache.maven.surefire.shared.lang3.StringUtils.isNotBlank;
import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
import java.util.Map;
@@ -255,13 +256,22 @@
.map( s -> s.substring( 1 + s.lastIndexOf( '.' ) ) )
.collect( joining( "," ) );
- boolean hasParams = !simpleClassNames.isEmpty();
+ boolean hasParams = isNotBlank( methodSource.getMethodParameterTypes() );
String methodName = methodSource.getMethodName();
- String methodSign = methodName + '(' + simpleClassNames + ')';
String description = testIdentifier.getLegacyReportingName();
- boolean useDesc = description.startsWith( methodSign );
- String methodDesc = hasParams ? ( useDesc ? description : methodSign ) : methodName;
- String methodDisp = methodSign.equals( display ) ? methodDesc : display;
+ String methodSign = hasParams ? methodName + '(' + simpleClassNames + ')' : methodName;
+ boolean equalDescriptions = display.equals( description );
+ boolean hasLegacyDescription = description.startsWith( methodName + '(' );
+ boolean hasDisplayName = !equalDescriptions || !hasLegacyDescription;
+ String methodDesc = equalDescriptions || !hasParams ? methodSign : description;
+ String methodDisp = hasDisplayName ? display : methodDesc;
+
+ // The behavior of methods getLegacyReportingName() and getDisplayName().
+ // test || legacy | display
+ // ==============||==========|==========
+ // normal || m() | m()
+ // normal+displ || displ | displ
+ // parameterized || m()[1] | displ
return new String[] {source[0], source[1], methodDesc, methodDisp};
}