[ 
https://issues.apache.org/jira/browse/SUREFIRE-1546?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16817248#comment-16817248
 ] 

Stig Rohde Døssing commented on SUREFIRE-1546:
----------------------------------------------

[~tibor17] I think JUnit already has the syntax needed for configuring the 
container name.

With the current JUnit syntax, you example would be written as
{code}
class DemoTest {
@ParameterizedTest(name = "a parameterized test (bar(int))") <-- This is the 
individual invocation name, where param index and value is available
@DisplayName(value = "bar({0})") <-- This is the name for the whole 
ParameterizedTest container

void bar(@ValueSource(intValue = {15, 54}) int x) {
    ...
}
}
{code}
When JUnit calls the RunListenerAdapter, the sequence of calls will be
{code}
executionStarted - { displayName: JUnit Jupiter, type: CONTAINER, source: null }
executionStarted - { displayName: DemoTest, type: CONTAINER, source: 
ClassSource [className = 'org.apache.surefire.stdout.corrupt.DemoTest'] }
executionStarted - { displayName: bar{{0}}, type: CONTAINER, source: 
MethodSource [className = 'org.apache.surefire.stdout.corrupt.DemoTest', 
methodName = 'bar'] } <-- ParameterizedTest container

executionStarted - { displayName: a parameterized test (bar(int)), type: TEST, 
source: MethodSource [...] } <-- First parameter invocation, 
executionFinished - { displayName: a parameterized test (bar(int)), type: TEST, 
source: MethodSource [...] } <-- First parameter invocation

executionStarted - { displayName: a parameterized test (bar(int)), type: TEST, 
source: MethodSource [...] } <-- Second parameter invocation
executionFinished - { displayName: a parameterized test (bar(int)), type: TEST, 
source: MethodSource [...] } <-- Second parameter invocation

executionFinished - { displayName: bar{{0}}, type: CONTAINER, source: 
MethodSource [...] } <-- ParameterizedTest container
executionFinished - { displayName: DemoTest, type: CONTAINER, source: 
ClassSource [...] }
executionFinished - { displayName: JUnit Jupiter, type: CONTAINER, source: null 
}
{code}

I think the RunListenerAdapter could build a stack of displayNames, where you 
add a name to the stack when executionStarted is called, and remove it when 
executionFinished is called. We should be able to build a tree like 
{code}
JUnit Jupiter
└── DemoTest
    └── a parameterized test (bar(int))
        ├── bar(0)
        └── bar(1)
{code}
that way.

The default DisplayName of the ParameterizedTest container is the method name 
and parameter types (so "bar(int)"), and the default DisplayName of the 
individual invocations is 
{code}
"[{index}] {arguments}"
{code}
So with no custom DisplayName or name parameter on ParameterizedTest, we get a 
DisplayName hierarchy of
{code}
JUnit Jupiter
└── DemoTest
    └── bar(int)
        ├── [1] 15
        └── [2] 54
{code}

I put a little example here if you want to play around with how JUnit calls the 
TestExecutionListener https://github.com/srdo/junit-5-test-listener. The 
sequence of calls is logged to test-out.log (stdout gets broken due to 
https://issues.apache.org/jira/browse/SUREFIRE-1659)

> JUnit 5 runner does not honor JUnit 5 display names
> ---------------------------------------------------
>
>                 Key: SUREFIRE-1546
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1546
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: JUnit 5.x support
>    Affects Versions: 2.22.0
>            Reporter: Romain Manni-Bucau
>            Assignee: Tibor Digana
>            Priority: Major
>              Labels: junit5
>             Fix For: 3.0.0-M4
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> JUnit 5 runner should respect the test @DisplayName instead of displaying the 
> classname if any is defined. Seems last release doesn't support that feature 
> of JUnit 5 making the console output and reports not the expected ones.
>  
> Origin: https://github.com/junit-team/junit5/issues/990



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to