junit-team/junit5 · error · JUnitException
Failed to initialize XML events writer
Error message
Failed to initialize XML events writer
What it means
Thrown by OpenTestReportGeneratingListener.testPlanExecutionStarted() as a JUnitException wrapping any failure from createDocumentWriter() or reportInfrastructure(). This is the top-level guard around XML events writer initialisation (socket or file mode) plus infrastructure/git reporting. The root cause is attached as the exception's cause.
Source
Thrown at junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java:143
}
@Override
public void testPlanExecutionStarted(TestPlan testPlan) {
ConfigurationParameters config = testPlan.getConfigurationParameters();
if (isEnabled(config)) {
NamespaceRegistry namespaceRegistry = NamespaceRegistry.builder(Namespace.REPORTING_CORE) //
.add("e", Namespace.REPORTING_EVENTS) //
.add("git", Namespace.REPORTING_GIT) //
.add("java", Namespace.REPORTING_JAVA) //
.add("junit", JUnitFactory.NAMESPACE, "https://schemas.junit.org/open-test-reporting/junit-1.9.xsd") //
.build();
outputDir = testPlan.getOutputDirectoryCreator().getRootDirectory();
try {
eventsFileWriter = createDocumentWriter(config, namespaceRegistry);
reportInfrastructure(config);
}
catch (Exception e) {
throw new JUnitException("Failed to initialize XML events writer", e);
}
}
}
private DocumentWriter<Events> createDocumentWriter(ConfigurationParameters config,
NamespaceRegistry namespaceRegistry) throws Exception {
return config.get(SOCKET_PROPERTY_NAME, Integer::valueOf) //
.map(port -> {
try {
Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);
Writer writer = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8);
return Events.createDocumentWriter(namespaceRegistry, writer);
}
catch (Exception e) {
throw new JUnitException("Failed to connect to socket on port " + port, e);
}
}) //
.orElseGet(() -> {View on GitHub (pinned to 956246301e)
Solutions
- Inspect the wrapped cause (getCause()) to identify socket, file, or git failure and address that specifically.
- If you do not need XML reporting, set junit.platform.reporting.open.xml.enabled=false (or leave unset).
- Ensure the output directory is writable and the socket port (if set) is listening.
- Align the opentest4j-reporting dependency version with the JUnit Platform version in use.
Example fix
// before junit.platform.reporting.open.xml.enabled = true # output dir read-only -> JUnitException on init // after junit.platform.reporting.open.xml.enabled = true junit.platform.output.dir = target/test-reports # writable
Defensive patterns
Strategy: try-catch
Validate before calling
// Only enable XML reporting when prerequisites hold
boolean enabled = Boolean.getBoolean("junit.platform.reporting.open.xml.enabled");
if (enabled) {
Path out = Path.of(System.getProperty("junit.platform.output.dir", "target"));
Files.createDirectories(out);
if (System.getProperty("junit.platform.reporting.open.xml.socket") != null
&& !socketListening(port)) enabled = false;
} Try / catch
try {
listener.testPlanExecutionStarted(testPlan);
} catch (JUnitException e) {
// log getCause(); disable reporting or fix env; tests can still run without the listener
log.warn("XML reporting init failed: {}", e.getMessage());
} Prevention
- Inspect the wrapped cause to target the real failure (socket/file/git).
- Enable XML reporting only in environments known to support it.
- Keep junit-platform-reporting and opentest4j-reporting versions aligned.
When it happens
Trigger: junit.platform.reporting.open.xml.enabled=true and either the socket connection fails, the events file cannot be created, NamespaceRegistry/DocumentWriter construction fails, or reportInfrastructure throws (e.g. git process failure). The broad catch at line 142-144 wraps all of these.
Common situations: Misconfigured socket port, unwritable output directory, git enabled but missing, or an incompatible opentest4j-reporting library version on the classpath. Enabling XML reporting in a restricted CI environment.
Related errors
- Failed to create XML events file
- Failed to close XML events file
- Failed to start process
- Failed to connect to socket on port
- Cannot override the standard style 'NONE'
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/158a42f566e1d60d.json.
Report an issue: GitHub.