sbt / sbt-jupiter-interface

Implementation of sbt's test interface for JUnit 5's Jupiter module
Apache License 2.0
33 stars 18 forks source link

@DisplayName annotation on Test not recognized #21

Open ShahBinoy opened 6 years ago

ShahBinoy commented 6 years ago

Once nice feature of JUnit 5 is overriding the outputs of test Method names with more human friendly @DisplayName annotation.

Seemingly the test output does not pick up the test names from @DisplayName but rather just shows the actual method name. Our actual method names are pretty long and not display friendly. The test result xml files should use the @DisplayName annotation.

ennru commented 5 years ago

I see you did something about this in your fork Did you propose the change as a pull request, @ShahBinoy?

maichler commented 5 years ago

While at it, would you fix #21 as well?

It's one thing to use @DisplayName for output rendering to the console, in fact TreePrintingTestListener supports this since the beginning (e.g. by running testOnly * -- "--display-mode=tree" or configuring test options testOptions += Tests.Argument(jupiterTestFramework, "--display-mode=tree").

Support in FlatPrintingTestListener could be done, I guess.

However, this is is about rendering to XML reporting files which is a totally different story.

JUnitXmlTestsListener is what generates those XML files. It receives the same test Events which SBT uses internally to identify tests and modifies the names (which are expected to be a fully qualified class name).

e.selector match {
    case selector: TestSelector => selector.testName.split('.').last
    case nested: NestedTestSelector => nested.suiteId().split('.').last + "." + nested.testName()
    case other => s"(It is not a test it is a ${other.getClass.getCanonicalName})"
}

Every test annotated with a @DisplayName containing a dot would be reported in parts only, if at all.

Then there is SBTs use of those events to identify available tests. Changing the selectors from class names to display names leads to a whole series of changes from where tests are collected to how tests are filtered.

Not sure how to proceed on this.

vasilmkd commented 2 months ago

FWIW, dynamicTest displayName is also not supported.

It is correctly shown in TreePrintingTestListener. It is not shown at all in FlatPrintingTestListener and of course not shown in XML reporting (an index is used instead).