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 6c6c8e968d..f9a650d3b5 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 @@ -43,6 +43,7 @@ import java.util.Map; import java.util.Optional; import java.util.Properties; +import java.util.HashSet; import java.util.logging.Logger; import org.apache.maven.surefire.providerapi.AbstractProvider; @@ -187,12 +188,12 @@ private LauncherDiscoveryRequest buildLauncherDiscoveryRequestForRerunFailures( LauncherDiscoveryRequestBuilder builder = request().filters( filters ).configurationParameters( configurationParameters ); // Iterate over recorded failures - for ( TestIdentifier identifier : adapter.getFailures().keySet() ) + for ( TestIdentifier identifier : new HashSet<>( adapter.getFailures().keySet() ) ) { // Extract quantified test name data String[] classMethodName = adapter.toClassMethodNameWithoutPlan( identifier ); - String className = classMethodName[1]; - String methodName = classMethodName[3]; + String className = classMethodName[0]; + String methodName = classMethodName[2]; // Add filter for the specific failing method builder.selectors( selectMethod( className, methodName ) ); } 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 feb169ca0d..954bb128f8 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 @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -211,6 +212,15 @@ public void rerunStillFailing() assertEquals( 1, summary.getTestsSucceededCount() ); assertEquals( 1, summary.getTestsAbortedCount() ); assertEquals( 3, summary.getTestsFailedCount() ); + Set failDisplays = new HashSet<>(); + for ( TestExecutionSummary.Failure failure : summary.getFailures() ) + { + failDisplays.add( failure.getTestIdentifier().getDisplayName() ); + } + assertEquals( 3, failDisplays.size() ); + assertTrue( failDisplays.contains( "Fails twice" ) ); + assertTrue( failDisplays.contains( "testAlwaysFail()" ) ); + assertTrue( failDisplays.contains( "testAlwaysError()" ) ); // Should rerun both of the failures summary = executionListener.summaries.get( 1 ); @@ -220,6 +230,15 @@ public void rerunStillFailing() assertEquals( 0, summary.getTestsSucceededCount() ); assertEquals( 0, summary.getTestsAbortedCount() ); assertEquals( 3, summary.getTestsFailedCount() ); + failDisplays.clear(); + for ( TestExecutionSummary.Failure failure : summary.getFailures() ) + { + failDisplays.add( failure.getTestIdentifier().getDisplayName() ); + } + assertEquals( 3, failDisplays.size() ); + assertTrue( failDisplays.contains( "Fails twice" ) ); + assertTrue( failDisplays.contains( "testAlwaysFail()" ) ); + assertTrue( failDisplays.contains( "testAlwaysError()" ) ); // now only one failure should remain summary = executionListener.summaries.get( 2 ); @@ -229,6 +248,14 @@ public void rerunStillFailing() assertEquals( 1, summary.getTestsSucceededCount() ); assertEquals( 0, summary.getTestsAbortedCount() ); assertEquals( 2, summary.getTestsFailedCount() ); + failDisplays.clear(); + for ( TestExecutionSummary.Failure failure : summary.getFailures() ) + { + failDisplays.add( failure.getTestIdentifier().getDisplayName() ); + } + assertEquals( 2, failDisplays.size() ); + assertTrue( failDisplays.contains( "testAlwaysFail()" ) ); + assertTrue( failDisplays.contains( "testAlwaysError()" ) ); } @Test @@ -834,6 +861,7 @@ static class TestClass4 { static int count; + @org.junit.jupiter.api.DisplayName( "Always passes" ) @org.junit.jupiter.api.Test void testPass() { @@ -843,7 +871,7 @@ void testPass() void testAborted() { assumeFalse( true ); - throw new IllegalStateException( "this exception should neve happen" ); + throw new IllegalStateException( "this exception should never happen" ); } @org.junit.jupiter.api.Test @@ -865,6 +893,7 @@ void testAlwaysSkipped() throw new IllegalStateException( "this test should be never called" ); } + @org.junit.jupiter.api.DisplayName( "Fails twice" ) @org.junit.jupiter.api.Test void testFailTwice() {