Skip to content

Commit 7ade5cc

Browse files
andpabslawekjaranowski
authored andcommitted
[SUREFIRE-2101] JUnit5 console reporting: Fall back to class name
If phrased console reporting is active, but no @DisplayName annotation is set, fall back to using the class name in console output
1 parent 61f03c6 commit 7ade5cc

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public Collection<WrappedReportEntry> getReportEntries()
297297
*/
298298
static String concatenateWithTestGroup( MessageBuilder builder, ReportEntry report, boolean phrasedClassName )
299299
{
300-
if ( phrasedClassName )
300+
if ( phrasedClassName && report.getReportNameWithGroup() != null )
301301
{
302302
return builder.strong( report.getReportNameWithGroup() )
303303
.toString();

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/TestSetStatsTest.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import static org.apache.maven.surefire.shared.utils.logging.MessageUtils.buffer;
3030
import static org.assertj.core.api.Assertions.assertThat;
31+
import static org.mockito.Mockito.atLeastOnce;
3132
import static org.mockito.Mockito.times;
3233
import static org.mockito.Mockito.verify;
3334
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -62,10 +63,27 @@ public void shouldConcatenateWithJUnit5TestGroup()
6263
when( reportEntry.getReportNameWithGroup() )
6364
.thenReturn( "pkg.MyTest (my group)" );
6465
String actual = TestSetStats.concatenateWithTestGroup( buffer(), reportEntry, true );
65-
verify( reportEntry, times( 1 ) ).getReportNameWithGroup();
66+
verify( reportEntry, atLeastOnce() ).getReportNameWithGroup();
6667
verifyNoMoreInteractions( reportEntry );
6768
String expected = buffer().strong( "pkg.MyTest (my group)" ).toString();
6869
assertThat( actual )
6970
.isEqualTo( expected );
7071
}
72+
73+
@Test
74+
public void shouldFallBackToTestGroupIfJUnit5TestGroupIsNull()
75+
{
76+
when( reportEntry.getReportNameWithGroup() )
77+
.thenReturn( null );
78+
when( reportEntry.getNameWithGroup() )
79+
.thenReturn( "pkg.MyTest (my group)" );
80+
String actual = TestSetStats.concatenateWithTestGroup( buffer(), reportEntry, true );
81+
verify( reportEntry, atLeastOnce() ).getReportNameWithGroup();
82+
verify( reportEntry, atLeastOnce() ).getNameWithGroup();
83+
verifyNoMoreInteractions( reportEntry );
84+
String expected = buffer().a( "pkg." ).strong( "MyTest (my group)" ).toString();
85+
assertThat( actual )
86+
.isEqualTo( expected );
87+
}
88+
7189
}

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import static org.hamcrest.CoreMatchers.is;
4040
import static org.hamcrest.CoreMatchers.not;
4141
import static org.hamcrest.CoreMatchers.startsWith;
42+
import static org.hamcrest.Matchers.matchesRegex;
4243
import static org.junit.Assert.assertThat;
4344
import static org.junit.Assume.assumeThat;
4445

@@ -366,7 +367,7 @@ public void testJupiterEngineWithExceptionMessage()
366367
}
367368

368369
@Test
369-
public void testJupiterEngineWithDisplayNames()
370+
public void testJupiterEngineWithDisplayNames() throws VerificationException
370371
{
371372
OutputValidator validator = unpack( "junit-platform-engine-jupiter", "-" + jupiter )
372373
.sysProp( "junit5.version", jupiter )
@@ -410,6 +411,12 @@ public void testJupiterEngineWithDisplayNames()
410411
+ "classname=\"junitplatformenginejupiter.BasicJupiterTest\"" )
411412
.assertContainsText( "<testcase name=\"add(int, int, int) 1 + 100 = 101\" "
412413
+ "classname=\"junitplatformenginejupiter.BasicJupiterTest\"" );
414+
415+
validator
416+
.assertThatLogLine( matchesRegex( ".*Running junitplatformenginejupiter.BasicJupiterTest$" ), is( 1 ) )
417+
.assertThatLogLine( matchesRegex( ".*Tests run.* junitplatformenginejupiter.BasicJupiterTest$" ), is( 1 ) )
418+
.assertThatLogLine( matchesRegex( ".*Running << . >>$" ), is( 1 ) )
419+
.assertThatLogLine( matchesRegex( ".*Tests run.* << . >>$" ), is( 1 ) );
413420
}
414421

415422
@Test

0 commit comments

Comments
 (0)