diff --git a/junit-console/src/main/java/org/junit/gen5/console/tasks/XmlReportWriter.java b/junit-console/src/main/java/org/junit/gen5/console/tasks/XmlReportWriter.java index 1873edcc716..edf947f018c 100644 --- a/junit-console/src/main/java/org/junit/gen5/console/tasks/XmlReportWriter.java +++ b/junit-console/src/main/java/org/junit/gen5/console/tasks/XmlReportWriter.java @@ -34,6 +34,7 @@ import org.junit.gen5.engine.TestExecutionResult; import org.junit.gen5.engine.reporting.ReportEntry; +import org.junit.gen5.engine.support.descriptor.JavaClassSource; import org.junit.gen5.launcher.TestIdentifier; class XmlReportWriter { @@ -111,11 +112,11 @@ private void writeSystemProperties(XMLStreamWriter writer) throws XMLStreamExcep private void writeTestcase(TestIdentifier test, NumberFormat numberFormat, XMLStreamWriter writer) throws XMLStreamException { + writer.writeStartElement("testcase"); writer.writeAttribute("name", test.getDisplayName()); - Optional parent = reportData.getTestPlan().getParent(test); - writer.writeAttribute("classname", parent.map(TestIdentifier::getName).orElse("")); + writer.writeAttribute("classname", getParentClassName(test)); writer.writeAttribute("time", getTime(test, numberFormat)); writer.writeComment("Unique ID: " + test.getUniqueId()); @@ -125,6 +126,17 @@ private void writeTestcase(TestIdentifier test, NumberFormat numberFormat, XMLSt writer.writeEndElement(); } + private String getParentClassName(TestIdentifier test) { + // @formatter:off + return reportData.getTestPlan().getParent(test) + .flatMap(TestIdentifier::getSource) + .filter(JavaClassSource.class::isInstance) + .map(JavaClassSource.class::cast) + .map(source -> source.getJavaClass().getName()) + .orElse(""); + // @formatter:on + } + private void writeSkippedOrErrorOrFailureElement(TestIdentifier test, XMLStreamWriter writer) throws XMLStreamException { if (reportData.wasSkipped(test)) { diff --git a/junit-launcher/src/main/java/org/junit/gen5/launcher/TestIdentifier.java b/junit-launcher/src/main/java/org/junit/gen5/launcher/TestIdentifier.java index 66145a24412..7648ab7be2f 100644 --- a/junit-launcher/src/main/java/org/junit/gen5/launcher/TestIdentifier.java +++ b/junit-launcher/src/main/java/org/junit/gen5/launcher/TestIdentifier.java @@ -39,7 +39,6 @@ public final class TestIdentifier implements Serializable { private final String uniqueId; private final String parentId; - private final String name; private final String displayName; private final Optional source; private final Set tags; @@ -52,7 +51,6 @@ public final class TestIdentifier implements Serializable { public static TestIdentifier from(TestDescriptor testDescriptor) { // TODO Use Flyweight Pattern for TestIdentifier? String uniqueId = testDescriptor.getUniqueId().toString(); - String name = testDescriptor.getName(); String displayName = testDescriptor.getDisplayName(); Optional source = testDescriptor.getSource(); Set tags = testDescriptor.getTags(); @@ -60,14 +58,13 @@ public static TestIdentifier from(TestDescriptor testDescriptor) { boolean container = !test || !testDescriptor.getChildren().isEmpty(); Optional parentId = testDescriptor.getParent().map( parentDescriptor -> parentDescriptor.getUniqueId().toString()); - return new TestIdentifier(uniqueId, name, displayName, source, tags, test, container, parentId); + return new TestIdentifier(uniqueId, displayName, source, tags, test, container, parentId); } - private TestIdentifier(String uniqueId, String name, String displayName, Optional source, - Set tags, boolean test, boolean container, Optional parentId) { + private TestIdentifier(String uniqueId, String displayName, Optional source, Set tags, + boolean test, boolean container, Optional parentId) { this.uniqueId = uniqueId; this.parentId = parentId.orElse(null); - this.name = name; this.displayName = displayName; this.source = (source != null ? source : Optional.empty()); this.tags = unmodifiableSet(new LinkedHashSet<>(tags)); @@ -95,16 +92,6 @@ public Optional getParentId() { return Optional.ofNullable(this.parentId); } - /** - * Get the name of the represented test or container. - * - *

The name is a technical name for a test or container. It - * must not be parsed or processed besides being displayed to end-users. - */ - public String getName() { - return this.name; - } - /** * Get the display name of the represented test or container. * @@ -170,7 +157,6 @@ public String toString() { return new ToStringBuilder(this) .append("uniqueId", this.uniqueId) .append("parentId", this.parentId) - .append("name", this.name) .append("displayName", this.displayName) .append("source", this.source) .append("tags", this.tags) diff --git a/junit-tests/src/test/java/org/junit/gen5/console/tasks/XmlReportsWritingListenerTests.java b/junit-tests/src/test/java/org/junit/gen5/console/tasks/XmlReportsWritingListenerTests.java index fba0c87fe93..4a44c92cd80 100644 --- a/junit-tests/src/test/java/org/junit/gen5/console/tasks/XmlReportsWritingListenerTests.java +++ b/junit-tests/src/test/java/org/junit/gen5/console/tasks/XmlReportsWritingListenerTests.java @@ -55,6 +55,9 @@ import org.junit.gen5.launcher.TestPlan; import org.opentest4j.AssertionFailedError; +/** + * @since 5.0 + */ @ExtendWith(TempDirectory.class) class XmlReportsWritingListenerTests { @@ -67,12 +70,13 @@ void writesFileForSingleSucceedingTest(@Root Path tempDirectory) throws Exceptio executeTests(engine, tempDirectory); String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml")); + //@formatter:off assertThat(content) .containsSequence( "", - "", "", "") @@ -200,8 +204,8 @@ void measuresTimesInSeconds(@Root Path tempDirectory) throws Exception { assertThat(content) .containsSequence( "