junit-team/junit5 · error · JUnitException

Failed to create output directory

Error message

Failed to create output directory

What it means

Thrown when configuration.getOutputDirectoryCreator().createOutputDirectory(testDescriptor) raises an IOException. This creator is responsible for materializing the directory tree that per-test published files land in; if directory creation itself fails the entire publish pathway is aborted before any file write is attempted.

Solutions

  1. Point junit.platform.output.dir at a writable, existing directory (or leave unset to use a temp dir).
  2. Grant write/execute permission to the test runner on the configured output path.
  3. If you registered a custom OutputDirectoryCreator, ensure its createOutputDirectory never throws on the happy path and logs the underlying IOException.

Example fix

// before: -Djunit.platform.output.dir=/opt/tests/out (read-only)
// after: -Djunit.platform.output.dir=$WORKSPACE/build/test-output
mkdir -p $WORKSPACE/build/test-output && chmod u+w $WORKSPACE/build/test-output
Defensive patterns

Strategy: validation

Validate before calling

Path base = Path.of(System.getProperty("junit.platform.output.dir", System.getProperty("java.io.tmpdir")));
if (!Files.exists(base) || !Files.isWritable(base)) {
    throw new IllegalStateException("Output base not writable: " + base);
}

Prevention

When it happens

Trigger: createOutputDirectory() raising IOException - e.g. the configured base output path is not writable, a parent path component exists as a regular file, or the filesystem refuses to create the per-test subdirectory.

Common situations: Running tests with junit.platform.outputdir / junit.platform.output.dir pointed at a read-only or nonexistent location, CI without write permission to the workspace, container with an overlay fs that denies mkdir, or a custom OutputDirectoryCreator misconfigured via JupiterConfiguration.

Related errors


AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11). Data as JSON: /api/errors/dd3dfc2e19fe6789. Report an issue: GitHub.

Appendix: source

Thrown at junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/AbstractExtensionContext.java:197

			() -> "name must not contain path separators: " + name);
		try {
			action.accept(path);
		}
		catch (Throwable t) {
			UnrecoverableExceptions.rethrowIfUnrecoverable(t);
			throw new JUnitException("Failed to publish path", t);
		}
		Preconditions.condition(Files.exists(path), () -> "Published path must exist: " + path);
		FileEntry fileEntry = fileEntryCreator.apply(path);
		this.engineExecutionListener.fileEntryPublished(this.testDescriptor, fileEntry);
	}

	private Path createOutputDirectory() {
		try {
			return configuration.getOutputDirectoryCreator().createOutputDirectory(this.testDescriptor);
		}
		catch (IOException e) {
			throw new JUnitException("Failed to create output directory", e);
		}
	}

	@Override
	public Optional<ExtensionContext> getParent() {
		return Optional.ofNullable(this.parent);
	}

	@Override
	public ExtensionContext getRoot() {
		if (this.parent != null) {
			return this.parent.getRoot();
		}
		return this;
	}

	protected T getTestDescriptor() {
		return this.testDescriptor;

View on GitHub (pinned to f070c699a0)