Skip to content

Commit ff69448

Browse files
committed
[SUREFIRE-2152] Include display-name of JUnit5 templated-tests in methodDesc
This includes the displayName (e.g. value of name="..." of a @ParameterizedTest) in the method description / test identifier. Provides more information than merely the invocation ID in case of failing tests, also for the console reporter. This can (especially if the actual list of arguments are quite large and/or dynamically determined at runtime) help a lot to identify which actual cases are the problematic ones.
1 parent 46ec3ba commit ff69448

File tree

1 file changed

+11
-2
lines changed
  • surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ private String[] toClassMethodName( TestIdentifier testIdentifier )
374374

375375
// Override resulting methodDesc/methodDisp values again, for invocations of
376376
// JUnit5 templated-tests (such as @ParameterizedTest/@RepeatedTest)
377+
// => Include the display-name of the actual invocation as well in the methodDesc of
378+
// each invocation (also according to the 'name=' values of such tests), to have
379+
// more context of what failed also e.g. from output of console reporter
377380
Integer templatedTestInvocationId = extractTemplatedInvocationId( testIdentifier );
378381
if ( templatedTestInvocationId != null )
379382
{
@@ -384,8 +387,14 @@ private String[] toClassMethodName( TestIdentifier testIdentifier )
384387
String methodSignature = methodName + '(' + simpleClassNames + ')';
385388

386389
String invocationIdStr = "[" + templatedTestInvocationId + "]";
387-
388-
methodDesc = methodSignature + invocationIdStr;
390+
String displayForDesc = display;
391+
if ( displayForDesc.startsWith( invocationIdStr ) )
392+
{
393+
// a bit hacky, try to prevent including ID multiple times in most default cases
394+
// "foo()[1][1] abc def" -> "foo()[1] abc def"
395+
displayForDesc = displayForDesc.substring( invocationIdStr.length() );
396+
}
397+
methodDesc = methodSignature + invocationIdStr + displayForDesc;
389398
methodDisp = parentDisplay + display;
390399
}
391400

0 commit comments

Comments
 (0)