Skip to content

Commit

Permalink
[SUREFIRE-1701] Use literal names instead of display names for classe…
Browse files Browse the repository at this point in the history
…s/methods for test reruns
  • Loading branch information
Col-E authored and Tibor17 committed Oct 28, 2019
1 parent 0595e4e commit c391947
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -211,6 +212,15 @@ public void rerunStillFailing()
assertEquals( 1, summary.getTestsSucceededCount() );
assertEquals( 1, summary.getTestsAbortedCount() );
assertEquals( 3, summary.getTestsFailedCount() );
Set<String> 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 );
Expand All @@ -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 );
Expand All @@ -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
Expand Down Expand Up @@ -834,6 +861,7 @@ static class TestClass4
{
static int count;

@org.junit.jupiter.api.DisplayName( "Always passes" )
@org.junit.jupiter.api.Test
void testPass()
{
Expand All @@ -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
Expand All @@ -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()
{
Expand Down

0 comments on commit c391947

Please sign in to comment.