You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/12/27 22:06:34 UTC
[maven-surefire] branch master updated: [SUREFIRE-2101] JUnit5 console reporting: Fall back to class name
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new 7ade5cc0d [SUREFIRE-2101] JUnit5 console reporting: Fall back to class name
7ade5cc0d is described below
commit 7ade5cc0d58b4966eea617b4bc069198a0f7d038
Author: Pabst, Andreas <an...@zeiss.com>
AuthorDate: Thu Dec 22 18:35:00 2022 +0100
[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
---
.../maven/plugin/surefire/report/TestSetStats.java | 2 +-
.../plugin/surefire/report/TestSetStatsTest.java | 20 +++++++++++++++++++-
.../maven/surefire/its/JUnitPlatformEnginesIT.java | 9 ++++++++-
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
index 869f58a5a..57c18241d 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
@@ -297,7 +297,7 @@ public class TestSetStats
*/
static String concatenateWithTestGroup( MessageBuilder builder, ReportEntry report, boolean phrasedClassName )
{
- if ( phrasedClassName )
+ if ( phrasedClassName && report.getReportNameWithGroup() != null )
{
return builder.strong( report.getReportNameWithGroup() )
.toString();
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/TestSetStatsTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/TestSetStatsTest.java
index 0d9bd6a48..8916fa217 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/TestSetStatsTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/TestSetStatsTest.java
@@ -28,6 +28,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import static org.apache.maven.surefire.shared.utils.logging.MessageUtils.buffer;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -62,10 +63,27 @@ public class TestSetStatsTest
when( reportEntry.getReportNameWithGroup() )
.thenReturn( "pkg.MyTest (my group)" );
String actual = TestSetStats.concatenateWithTestGroup( buffer(), reportEntry, true );
- verify( reportEntry, times( 1 ) ).getReportNameWithGroup();
+ verify( reportEntry, atLeastOnce() ).getReportNameWithGroup();
verifyNoMoreInteractions( reportEntry );
String expected = buffer().strong( "pkg.MyTest (my group)" ).toString();
assertThat( actual )
.isEqualTo( expected );
}
+
+ @Test
+ public void shouldFallBackToTestGroupIfJUnit5TestGroupIsNull()
+ {
+ when( reportEntry.getReportNameWithGroup() )
+ .thenReturn( null );
+ when( reportEntry.getNameWithGroup() )
+ .thenReturn( "pkg.MyTest (my group)" );
+ String actual = TestSetStats.concatenateWithTestGroup( buffer(), reportEntry, true );
+ verify( reportEntry, atLeastOnce() ).getReportNameWithGroup();
+ verify( reportEntry, atLeastOnce() ).getNameWithGroup();
+ verifyNoMoreInteractions( reportEntry );
+ String expected = buffer().a( "pkg." ).strong( "MyTest (my group)" ).toString();
+ assertThat( actual )
+ .isEqualTo( expected );
+ }
+
}
diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java
index cbb3b422b..c63bb5631 100644
--- a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java
+++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java
@@ -39,6 +39,7 @@ import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.Matchers.matchesRegex;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeThat;
@@ -366,7 +367,7 @@ public class JUnitPlatformEnginesIT extends SurefireJUnit4IntegrationTestCase
}
@Test
- public void testJupiterEngineWithDisplayNames()
+ public void testJupiterEngineWithDisplayNames() throws VerificationException
{
OutputValidator validator = unpack( "junit-platform-engine-jupiter", "-" + jupiter )
.sysProp( "junit5.version", jupiter )
@@ -410,6 +411,12 @@ public class JUnitPlatformEnginesIT extends SurefireJUnit4IntegrationTestCase
+ "classname=\"junitplatformenginejupiter.BasicJupiterTest\"" )
.assertContainsText( "<testcase name=\"add(int, int, int) 1 + 100 = 101\" "
+ "classname=\"junitplatformenginejupiter.BasicJupiterTest\"" );
+
+ validator
+ .assertThatLogLine( matchesRegex( ".*Running junitplatformenginejupiter.BasicJupiterTest$" ), is( 1 ) )
+ .assertThatLogLine( matchesRegex( ".*Tests run.* junitplatformenginejupiter.BasicJupiterTest$" ), is( 1 ) )
+ .assertThatLogLine( matchesRegex( ".*Running << . >>$" ), is( 1 ) )
+ .assertThatLogLine( matchesRegex( ".*Tests run.* << . >>$" ), is( 1 ) );
}
@Test