-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JUnit-specific metadata to open-test-reporting's HTML report (#4116)
When creating the event-based XML report, the `OpenTestReportGeneratingListener` includes JUnit-specific metadata: type, unique ID, and legacy reporting name. This PR implements open-test-reporting's `Contributor` SPI to include that data in the new HTML report of open-test-reporting. Moreover, it configures the build to create a single report for all test tasks per subproject and uploads it as part of GitHub Action runs.
- Loading branch information
1 parent
be4edac
commit 5e2b694
Showing
28 changed files
with
343 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...tform-reporting/src/main/java/org/junit/platform/reporting/open/xml/JUnitContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.reporting.open.xml; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static java.util.Collections.singletonList; | ||
import static org.apiguardian.api.API.Status.INTERNAL; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.apiguardian.api.API; | ||
import org.opentest4j.reporting.schema.Namespace; | ||
import org.opentest4j.reporting.tooling.spi.htmlreport.Contributor; | ||
import org.opentest4j.reporting.tooling.spi.htmlreport.KeyValuePairs; | ||
import org.opentest4j.reporting.tooling.spi.htmlreport.Section; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
/** | ||
* Contributes a section containing JUnit-specific metadata for each test node | ||
* to the open-test-reporting HTML report. | ||
* | ||
* @since 1.12 | ||
*/ | ||
@SuppressWarnings("exports") // we don't want to export 'org.opentest4j.reporting.tooling.spi' transitively | ||
@API(status = INTERNAL, since = "1.12") | ||
public class JUnitContributor implements Contributor { | ||
|
||
public JUnitContributor() { | ||
} | ||
|
||
@Override | ||
public List<Section> contributeSectionsForTestNode(Element testNodeElement) { | ||
return findChild(testNodeElement, Namespace.REPORTING_CORE, "metadata") // | ||
.map(metadata -> { | ||
Map<String, String> table = new LinkedHashMap<>(); | ||
findChild(metadata, JUnitFactory.NAMESPACE, "type") // | ||
.map(Node::getTextContent) // | ||
.ifPresent(value -> table.put("Type", value)); | ||
findChild(metadata, JUnitFactory.NAMESPACE, "uniqueId") // | ||
.map(Node::getTextContent) // | ||
.ifPresent(value -> table.put("Unique ID", value)); | ||
findChild(metadata, JUnitFactory.NAMESPACE, "legacyReportingName") // | ||
.map(Node::getTextContent) // | ||
.ifPresent(value -> table.put("Legacy reporting name", value)); | ||
return table; | ||
}) // | ||
.filter(table -> !table.isEmpty()) // | ||
.map(table -> singletonList(Section.builder() // | ||
.title("JUnit metadata") // | ||
.order(15) // | ||
.addBlock(KeyValuePairs.builder().content(table).build()) // | ||
.build())) // | ||
.orElse(emptyList()); | ||
} | ||
|
||
private static Optional<Node> findChild(Node parent, Namespace namespace, String localName) { | ||
NodeList children = parent.getChildNodes(); | ||
for (int i = 0; i < children.getLength(); i++) { | ||
Node child = children.item(i); | ||
if (localName.equals(child.getLocalName()) && namespace.getUri().equals(child.getNamespaceURI())) { | ||
return Optional.of(child); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...n/resources/META-INF/services/org.opentest4j.reporting.tooling.spi.htmlreport.Contributor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.junit.platform.reporting.open.xml.JUnitContributor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...org/junit/platform/reporting/open/xml/OpenTestReportGenerationSystemPropertyOverride.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.reporting.open.xml; | ||
|
||
import static org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener.ENABLED_PROPERTY_NAME; | ||
|
||
import org.junit.jupiter.api.extension.AfterTestExecutionCallback; | ||
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
public class OpenTestReportGenerationSystemPropertyOverride | ||
implements BeforeTestExecutionCallback, AfterTestExecutionCallback { | ||
|
||
@Override | ||
public void beforeTestExecution(ExtensionContext context) { | ||
var oldValue = System.clearProperty(ENABLED_PROPERTY_NAME); | ||
getStore(context).put(ENABLED_PROPERTY_NAME, oldValue); | ||
} | ||
|
||
@Override | ||
public void afterTestExecution(ExtensionContext context) { | ||
var oldValue = getStore(context).get(ENABLED_PROPERTY_NAME, String.class); | ||
if (oldValue == null) { | ||
System.clearProperty(ENABLED_PROPERTY_NAME); | ||
} | ||
else { | ||
System.setProperty(ENABLED_PROPERTY_NAME, oldValue); | ||
} | ||
} | ||
|
||
private static ExtensionContext.Store getStore(ExtensionContext context) { | ||
return context.getStore( | ||
ExtensionContext.Namespace.create(OpenTestReportGenerationSystemPropertyOverride.class)); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ng/src/testFixtures/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.junit.platform.reporting.open.xml.OpenTestReportGenerationSystemPropertyOverride |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.