junit-team/junit5 · critical · JUnitException

Error executing tests for engine ${getId()}

Error message

Error executing tests for engine ${getId()}

What it means

Thrown by HierarchicalTestEngine.execute (line 62-72) as a catch-all JUnitException wrapping any Exception that escapes the try-with-resources block around the executor service, execution context, and the HierarchicalTestExecutor.execute().get() call. It names the engine via getId() so the caller knows which engine failed.

Source

Thrown at junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/HierarchicalTestEngine.java:70

	 *
	 * <p>Supports cancellation via the {@link CancellationToken} passed in the
	 * supplied {@code request}.
	 *
	 * @see Node
	 * @see #createExecutorService
	 * @see #createExecutionContext
	 * @see #createThrowableCollectorFactory
	 */
	@Override
	public final void execute(ExecutionRequest request) {
		try (HierarchicalTestExecutorService executorService = createExecutorService(request)) {
			C executionContext = createExecutionContext(request);
			ThrowableCollector.Factory throwableCollectorFactory = createThrowableCollectorFactory(request);
			new HierarchicalTestExecutor<>(request, executionContext, executorService,
				throwableCollectorFactory).execute().get();
		}
		catch (Exception exception) {
			throw new JUnitException("Error executing tests for engine " + getId(), exception);
		}
	}

	/**
	 * Create the {@linkplain HierarchicalTestExecutorService executor service}
	 * to use for executing the supplied {@linkplain ExecutionRequest request}.
	 *
	 * <p>An engine may use the information in the supplied <em>request</em>
	 * such as the contained
	 * {@linkplain ExecutionRequest#getConfigurationParameters() configuration parameters}
	 * to decide what kind of service to return or how to configure it.
	 *
	 * <p>By default, this method returns an instance of
	 * {@link SameThreadHierarchicalTestExecutorService}.
	 *
	 * @param request the request about to be executed
	 * @since 1.3
	 * @see ForkJoinPoolHierarchicalTestExecutorService

View on GitHub (pinned to 956246301e)

Solutions

  1. Inspect the caused-by exception; it is the real failure. Fix that root cause.
  2. If the cause is an ExecutionException, unwrap one more level to reach the actual test/extension error.
  3. Verify createExecutorService / createExecutionContext implementations for custom engines do not throw for valid requests.
  4. Check for parallel-execution configuration issues if ForkJoinPool/WorkerThreadPool creation is in the stack.

Example fix

// before: custom engine context throws
@Override protected EngineExecutionContext createExecutionContext(ExecutionRequest r) {
    return contextFactory.build(); // throws -> wraps as 'Error executing tests for engine ...'
}

// after: defensive construction with clear error
@Override protected EngineExecutionContext createExecutionContext(ExecutionRequest r) {
    try { return contextFactory.build(); }
    catch (IllegalStateException e) {
        throw new JUnitException("Could not build execution context", e);
    }
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    engine.execute(request);
} catch (JUnitException e) {
    Throwable cause = e.getCause();
    // cause is the real failure (often ExecutionException with another cause)
    log.error("engine {} failed", engine.getId(), cause);
    throw cause != null ? cause : e;
}

Prevention

When it happens

Trigger: Any uncaught Exception during execution setup/teardown: createExecutorService throws, createExecutionContext throws, the executor's Future.get() throws (ExecutionException wrapping a test/extension error), or close() on the executor service throws. Test-level assertion failures are normally collected by ThrowableCollector and do not surface here.

Common situations: A broken @RegisterExtension or @TestInstance factory throwing during context creation; parallel executor misconfiguration (see error 113) surfacing through execute(); a custom HierarchicalTestEngine whose createExecutionContext throws; interrupted execution where the executor future fails.

Related errors


AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04). Data as JSON: /data/errors/603a4a7b21295562.json. Report an issue: GitHub.