junit-team/junit5 · error · JUnitException
Failed to create XML events file
Error message
Failed to create XML events file
What it means
Thrown by OpenTestReportGeneratingListener.createDocumentWriter() (file-mode branch) as a JUnitException when Events.createDocumentWriter for open-test-report.xml under outputDir fails. Reached only when socket mode is not configured; the exception wraps the underlying I/O or XML failure.
Source
Thrown at junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java:167
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(() -> {
try {
Path eventsXml = requireNonNull(outputDir).resolve("open-test-report.xml");
return Events.createDocumentWriter(namespaceRegistry, eventsXml);
}
catch (Exception e) {
throw new JUnitException("Failed to create XML events file", e);
}
});
}
private boolean isEnabled(ConfigurationParameters config) {
return config.getBoolean(ENABLED_PROPERTY_NAME).orElse(false);
}
private boolean isGitEnabled(ConfigurationParameters config) {
return config.getBoolean(GIT_ENABLED_PROPERTY_NAME).orElse(false);
}
@SuppressWarnings("EmptyCatch")
private void reportInfrastructure(ConfigurationParameters config) {
eventsFileWriter.append(infrastructure(), infrastructure -> {
try {
String hostName = InetAddress.getLocalHost().getHostName();
infrastructure.append(hostName(hostName));View on GitHub (pinned to 956246301e)
Solutions
- Set junit.platform.output.dir to a writable, unique directory.
- Ensure the output directory persists for the whole test run (do not clean it mid-run).
- Inspect getCause() for the precise I/O error.
- If reporting is optional, set junit.platform.reporting.open.xml.enabled=false.
Example fix
# before
junit.platform.reporting.open.xml.enabled = true
# output dir read-only -> JUnitException
# after
junit.platform.reporting.open.xml.enabled = true
junit.platform.output.dir = target/test-reports-${random.uuid} Defensive patterns
Strategy: try-catch
Validate before calling
Path out = testPlan.getOutputDirectoryCreator().getRootDirectory();
Files.createDirectories(out);
if (!Files.isWritable(out)) throw new IllegalStateException("output dir not writable: " + out); Type guard
static boolean canWriteEventsFile(Path dir) {
Path f = dir.resolve("open-test-report.xml");
try { Files.createDirectories(dir); return Files.isWritable(dir); }
catch (IOException e) { return false; }
} Try / catch
try {
Events.createDocumentWriter(ns, outputDir.resolve("open-test-report.xml"));
} catch (Exception e) {
// fall back to a temp dir, or disable reporting
} Prevention
- Set junit.platform.output.dir to a writable, unique path.
- Keep the output dir alive for the whole run; do not delete it mid-test.
- Pre-flight check disk space and permissions in CI.
When it happens
Trigger: XML reporting enabled, no socket property set, and outputDir (from the TestPlan's OutputDirectoryCreator, rooted at OutputDir) cannot host open-test-report.xml - e.g. directory missing, read-only, or the XML writer cannot initialise the file.
Common situations: Output directory deleted or made read-only between discovery and execution. Disk full. Concurrent test runs colliding on the same non-unique output dir. Misconfigured junit.platform.output.dir.
Related errors
- Failed to close XML events file
- Could not open color palette properties file
- Failed to retrieve canonical path for file: ${file}
- Failed to retrieve canonical path for directory: ${directory
- Failed to retrieve canonical path for directory: ${directory
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/55c2760bc913d776.json.
Report an issue: GitHub.