Skip to content

Commit e8f65b9

Browse files
olamyTibor17
authored andcommitted
[SUREFIRE-1797] Surefire report with parameterized tests contain all names of test the same
1 parent 2e14ba6 commit e8f65b9

File tree

4 files changed

+150
-6
lines changed

4 files changed

+150
-6
lines changed

surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformRerunFailingTestsIT.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,26 @@ public void testRerunOneTestMethod()
203203
verifyFailuresOneRetryOneMethod( outputValidator );
204204
}
205205

206+
@Test
207+
public void testParameterizedTest()
208+
{
209+
unpack()
210+
.setJUnitVersion( VERSION )
211+
.maven()
212+
.activateProfile( "parameters" )
213+
.withFailure()
214+
.debugLogging()
215+
.executeTest()
216+
.assertTestSuiteResults( 6, 0, 1, 1, 0 )
217+
.getSurefireReportsXmlFile( "TEST-junitplatform.ParametersTest.xml" )
218+
.assertContainsText( "testOneFailingPassingTest(ConnectionPoolFactory)[1]" )
219+
.assertContainsText( "testOneFailingPassingTest(ConnectionPoolFactory)[2]" )
220+
.assertContainsText( "testOneFailingPassingTest(ConnectionPoolFactory)[3]" )
221+
.assertContainsText( "testAllPassingTest(ConnectionPoolFactory)[1]" )
222+
.assertContainsText( "testAllPassingTest(ConnectionPoolFactory)[2]" )
223+
.assertContainsText( "testAllPassingTest(ConnectionPoolFactory)[3]" );
224+
}
225+
206226
private void verifyFailuresOneRetryAllClasses( OutputValidator outputValidator )
207227
{
208228
verifyFailuresOneRetry( outputValidator, 5, 1, 1, 0 );

surefire-its/src/test/resources/junit-platform-rerun-failing-tests/pom.xml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,54 @@
4040
<version>${junit.version}</version>
4141
<scope>test</scope>
4242
</dependency>
43+
<dependency>
44+
<groupId>org.junit.jupiter</groupId>
45+
<artifactId>junit-jupiter-params</artifactId>
46+
<version>${junit.version}</version>
47+
<scope>test</scope>
48+
</dependency>
4349
</dependencies>
4450

4551
<build>
52+
<pluginManagement>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-surefire-plugin</artifactId>
57+
<version>${surefire.version}</version>
58+
</plugin>
59+
</plugins>
60+
</pluginManagement>
4661
<plugins>
4762
<plugin>
4863
<groupId>org.apache.maven.plugins</groupId>
4964
<artifactId>maven-surefire-plugin</artifactId>
50-
<version>${surefire.version}</version>
65+
<configuration>
66+
<excludes>
67+
<exclude>**/ParametersTest.java</exclude>
68+
</excludes>
69+
</configuration>
5170
</plugin>
5271
</plugins>
5372
</build>
73+
<profiles>
74+
<profile>
75+
<id>parameters</id>
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-surefire-plugin</artifactId>
81+
<configuration>
82+
<excludes>
83+
<exclude>**/PassingTest.java</exclude>
84+
<exclude>**/FlakyFirstTimeTest.java</exclude>
85+
</excludes>
86+
</configuration>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
</profile>
91+
</profiles>
5492

5593
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package junitplatform;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.Assumptions;
25+
import org.junit.jupiter.params.ParameterizedTest;
26+
import org.junit.jupiter.params.provider.MethodSource;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
30+
import java.util.stream.Stream;
31+
32+
33+
public class ParametersTest
34+
{
35+
public static Stream<ConnectionPoolFactory> pools()
36+
{
37+
return Stream.of( new ConnectionPoolFactory( "duplex" ),
38+
new ConnectionPoolFactory( "multiplex" ),
39+
new ConnectionPoolFactory( "round-robin" ) );
40+
}
41+
42+
@ParameterizedTest
43+
@MethodSource( "pools" )
44+
public void testAllPassingTest( ConnectionPoolFactory factory )
45+
{
46+
System.out.println( "testAllPassingTest factory " + factory );
47+
}
48+
49+
@ParameterizedTest
50+
@MethodSource( "pools" )
51+
public void testOneFailingPassingTest( ConnectionPoolFactory factory ) throws Exception
52+
{
53+
Assumptions.assumeFalse( factory.name.equals( "round-robin" ) );
54+
System.out.println( "Passing test factory " + factory );
55+
if ( factory.name.equals( "multiplex" ) )
56+
{
57+
assertEquals( 1, 2 );
58+
}
59+
}
60+
61+
private static class ConnectionPoolFactory
62+
{
63+
private final String name;
64+
65+
private ConnectionPoolFactory( String name )
66+
{
67+
this.name = name;
68+
}
69+
70+
@Override
71+
public String toString()
72+
{
73+
return name;
74+
}
75+
}
76+
}

surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static java.util.Collections.emptyMap;
2323
import static java.util.stream.Collectors.joining;
2424
import static org.apache.maven.surefire.api.util.internal.ObjectUtils.systemProps;
25+
import static org.apache.maven.surefire.shared.lang3.StringUtils.isNotBlank;
2526
import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
2627

2728
import java.util.Map;
@@ -255,13 +256,22 @@ private String[] toClassMethodName( TestIdentifier testIdentifier )
255256
.map( s -> s.substring( 1 + s.lastIndexOf( '.' ) ) )
256257
.collect( joining( "," ) );
257258

258-
boolean hasParams = !simpleClassNames.isEmpty();
259+
boolean hasParams = isNotBlank( methodSource.getMethodParameterTypes() );
259260
String methodName = methodSource.getMethodName();
260-
String methodSign = methodName + '(' + simpleClassNames + ')';
261261
String description = testIdentifier.getLegacyReportingName();
262-
boolean useDesc = description.startsWith( methodSign );
263-
String methodDesc = hasParams ? ( useDesc ? description : methodSign ) : methodName;
264-
String methodDisp = methodSign.equals( display ) ? methodDesc : display;
262+
String methodSign = hasParams ? methodName + '(' + simpleClassNames + ')' : methodName;
263+
boolean equalDescriptions = display.equals( description );
264+
boolean hasLegacyDescription = description.startsWith( methodName + '(' );
265+
boolean hasDisplayName = !equalDescriptions || !hasLegacyDescription;
266+
String methodDesc = equalDescriptions || !hasParams ? methodSign : description;
267+
String methodDisp = hasDisplayName ? display : methodDesc;
268+
269+
// The behavior of methods getLegacyReportingName() and getDisplayName().
270+
// test || legacy | display
271+
// ==============||==========|==========
272+
// normal || m() | m()
273+
// normal+displ || displ | displ
274+
// parameterized || m()[1] | displ
265275

266276
return new String[] {source[0], source[1], methodDesc, methodDisp};
267277
}

0 commit comments

Comments
 (0)