Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic testcase name in xml report is not the same as display-name #4312

Closed
gtach2o opened this issue Feb 12, 2025 · 6 comments
Closed

Dynamic testcase name in xml report is not the same as display-name #4312

gtach2o opened this issue Feb 12, 2025 · 6 comments

Comments

@gtach2o
Copy link

gtach2o commented Feb 12, 2025

Hello,

I'm using DynamicTest with @TestFactory all works as expected except xml report generated during execution with console launcher.
The test name set during execution is not propagated to name attribute of testcase node in xml report.

...
String testName = "Test " + index + " - " + page.page();
return DynamicTest.dynamicTest(testName, () -> {
  assertAll(
   () -> assertTrue(test(), page.page())
      );
});
<testcase name="dynamicTests()[17]" classname="foo.bar.ClassName" time="0.001">
        <system-out><![CDATA[
unique-id: [engine:junit-jupiter]/[class:foo.bar.ClassName]/[test-factory:dynamicTests()]/[dynamic-test:#17]
display-name: Test 17 - page.asp
]]></system-out>
    </testcase>

as you can see display-name is correct in CDATA, but attribute is not updated with display name name="dynamicTests()[17]"

expected

<testcase name="Test 17 - page.asp" classname="foo.bar.ClassName" time="0.001">
        <system-out><![CDATA[
unique-id: [engine:junit-jupiter]/[class:foo.bar.ClassName]/[test-factory:dynamicTests()]/[dynamic-test:#17]
display-name: Test 17 - page.asp
]]></system-out>
    </testcase>

I was trying to use TestReporter.publishEntry
Stream<DynamicTest> dynamicTests(TestReporter testReporter)
It didn't work out either.

Context

  • Used versions junit-platform-console-standalone-1.11.4.jar
  • JRE 23
@marcphilipp
Copy link
Member

That's by design. For compatibility with existing tools the legacy XML format outputs the legacy reporting name.

Please give the new Open Test Reporting XML format a try to get support for display names, report entries, hierarchical test structures, etc.

@marcphilipp marcphilipp closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2025
Copy link

Please assign a status label to this issue.

@github-actions github-actions bot reopened this Feb 12, 2025
@marcphilipp marcphilipp closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2025
@gtach2o
Copy link
Author

gtach2o commented Feb 12, 2025

That's by design. For compatibility with existing tools the legacy XML format outputs the legacy reporting name.

Please give the new Open Test Reporting XML format a try to get support for display names, report entries, hierarchical test structures, etc.

I added --config=junit.platform.reporting.open.xml.enabled=true, but seems like it doesn't work

WARNING: TestExecutionListener [org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener] threw exception for method: executionFinished(TestIdentifier [uniqueId = [engine:junit-jupiter], parentId = null, displayName = 'JUnit Jupiter', legacyReportingName = 'JUnit Jupiter', source = null, tags = [], type = CONTAINER], TestExecutionResult [status = SUCCESSFUL, throwable = null])
java.lang.RuntimeException: Failed to write event: Element{domElement=[e:finished: null]}
        at org.junit.platform.reporting.shadow.org.opentest4j.reporting.events.api.DefaultDocumentWriter.append(DefaultDocumentWriter.java:118)
        at org.junit.platform.reporting.shadow.org.opentest4j.reporting.events.api.DefaultDocumentWriter.append(DefaultDocumentWriter.java:42)
        at org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener.executionFinished(OpenTestReportGeneratingListener.java:247)
        at org.junit.platform.launcher.core.CompositeTestExecutionListener.lambda$executionFinished$10(CompositeTestExecutionListener.java:73)
        at org.junit.platform.launcher.core.CompositeTestExecutionListener.lambda$notifyEach$19(CompositeTestExecutionListener.java:102)
        at org.junit.platform.commons.util.CollectionUtils.forEachInReverseOrder(CollectionUtils.java:244)
        at org.junit.platform.launcher.core.IterationOrder$2.forEach(IterationOrder.java:30)
        at org.junit.platform.launcher.core.CompositeTestExecutionListener.notifyEach(CompositeTestExecutionListener.java:100)
        at org.junit.platform.launcher.core.CompositeTestExecutionListener.executionFinished(CompositeTestExecutionListener.java:72)
        at org.junit.platform.launcher.core.ExecutionListenerAdapter.executionFinished(ExecutionListenerAdapter.java:56)
        at org.junit.platform.launcher.core.CompositeEngineExecutionListener.lambda$executionFinished$6(CompositeEngineExecutionListener.java:59)
        at org.junit.platform.launcher.core.CompositeEngineExecutionListener.lambda$notifyEach$11(CompositeEngineExecutionListener.java:74)
        at org.junit.platform.commons.util.CollectionUtils.forEachInReverseOrder(CollectionUtils.java:244)
        at org.junit.platform.launcher.core.IterationOrder$2.forEach(IterationOrder.java:30)
        at org.junit.platform.launcher.core.CompositeEngineExecutionListener.notifyEach(CompositeEngineExecutionListener.java:72)
        at org.junit.platform.launcher.core.CompositeEngineExecutionListener.executionFinished(CompositeEngineExecutionListener.java:58)
        at org.junit.platform.launcher.core.DelegatingEngineExecutionListener.executionFinished(DelegatingEngineExecutionListener.java:46)
        at org.junit.platform.launcher.core.StackTracePruningEngineExecutionListener.executionFinished(StackTracePruningEngineExecutionListener.java:46)
        at org.junit.platform.launcher.core.DelegatingEngineExecutionListener.executionFinished(DelegatingEngineExecutionListener.java:46)
        at org.junit.platform.launcher.core.OutcomeDelayingEngineExecutionListener.reportEngineOutcome(OutcomeDelayingEngineExecutionListener.java:69)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:199)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:169)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:93)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:58)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:141)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:57)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:103)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85)
        at org.junit.platform.launcher.core.DelegatingLauncher.execute(DelegatingLauncher.java:47)
        at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:63)
        at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:102)
        at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$1(ConsoleTestExecutor.java:71)
        at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.replaceThreadContextClassLoaderAndInvoke(CustomContextClassLoaderExecutor.java:42)
        at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
        at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:71)
        at org.junit.platform.console.options.ExecuteTestsCommand.execute(ExecuteTestsCommand.java:61)
        at org.junit.platform.console.options.ExecuteTestsCommand.execute(ExecuteTestsCommand.java:27)
        at org.junit.platform.console.options.BaseCommand.call(BaseCommand.java:81)
        at org.junit.platform.console.shadow.picocli.CommandLine.executeUserObject(CommandLine.java:2045)
        at org.junit.platform.console.shadow.picocli.CommandLine.access$1500(CommandLine.java:148)
        at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2465)
        at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.handle(CommandLine.java:2457)
        at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.handle(CommandLine.java:2419)
        at org.junit.platform.console.shadow.picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2277)
        at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.execute(CommandLine.java:2421)
        at org.junit.platform.console.shadow.picocli.CommandLine.execute(CommandLine.java:2174)
        at org.junit.platform.console.options.MainCommand.runCommand(MainCommand.java:146)
        at org.junit.platform.console.options.MainCommand.run(MainCommand.java:139)
        at org.junit.platform.console.options.CommandFacade.run(CommandFacade.java:54)
        at org.junit.platform.console.options.CommandFacade.run(CommandFacade.java:37)
        at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:33)
Caused by: java.lang.NullPointerException: Cannot invoke "java.io.Writer.flush()" because "this.fWriter" is null
        at java.xml/com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.flush(XMLStreamWriterImpl.java:397)
        at org.junit.platform.reporting.shadow.org.opentest4j.reporting.events.api.DefaultDocumentWriter.writeNewLine(DefaultDocumentWriter.java:139)
        at org.junit.platform.reporting.shadow.org.opentest4j.reporting.events.api.DefaultDocumentWriter.append(DefaultDocumentWriter.java:112)
        ... 50 more

@gtach2o
Copy link
Author

gtach2o commented Feb 12, 2025

@marcphilipp
We can try to use OTR format despite it will take time to implement it's parser, but we need to see actual test names now.
Is there any way to workaround updating name attribute in testcase during DynamicTest execution?

@marcphilipp
Copy link
Member

We can try to use OTR format despite it will take time to implement it's parser

You mean your build server or other tooling will need time to support the new format or what did you have in mind?

Is there any way to workaround updating name attribute in testcase during DynamicTest execution?

No, that's not configurable/changeable.

@gtach2o
Copy link
Author

gtach2o commented Feb 12, 2025

We have a web service which shows test results in a nice way from any test report, junit, xunit, cucumber.
OTR is a new format which needs to be supported first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants