junit-team/junit5 · info · TestAbortedException
Assumption failed:
Error message
Assumption failed:
What it means
Thrown as a TestAbortedException (subclass of org.opentest4j.TestAbortedException) by the private throwAssumptionFailed helper when an Assumptions.assumeTrue/assumeFalse/assumeNotNull call fails AND a non-blank message was supplied. Aborted tests are reported as skipped/aborted, NOT as failures — this is intended conditional-test-execution behavior, not a bug. JUnit throws it so that environment-dependent tests do not register as failures when their preconditions do not hold.
Source
Thrown at junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assumptions.java:339
*
* <p>See Javadoc for {@link #abort(String)} for an explanation of this
* method's generic return type {@code V}.
*
* @param messageSupplier the supplier of the message to be included in the
* {@code TestAbortedException}
* @throws TestAbortedException always
* @since 5.9
*/
@Contract("_ -> fail")
@API(status = STABLE, since = "5.9")
@SuppressWarnings("TypeParameterUnusedInFormals")
public static <V> V abort(Supplier<String> messageSupplier) {
throw new TestAbortedException(messageSupplier.get());
}
@Contract("_ -> fail")
private static void throwAssumptionFailed(@Nullable String message) {
throw new TestAbortedException(
StringUtils.isNotBlank(message) ? "Assumption failed: " + message : "Assumption failed");
}
}
View on GitHub (pinned to 956246301e)
Solutions
- Treat the abort as expected: verify the precondition really should hold in this environment and set the required env var / start the required service.
- If the precondition is genuinely optional, leave the test aborted — this is the correct outcome, not something to 'fix'.
- Tighten or correct the assumption predicate if it is too strict (e.g., wrong env var name, inverted logic).
- Move truly optional tests to a separate tagged suite (@Tag) and exclude them in CI rather than aborting at runtime.
Example fix
// before
assumeTrue("http://svc".equals(System.getenv("SVC_URL")), "requires SVC_URL");
// after — set the env var, or guard the whole test:
@EnabledIfEnvironmentVariable(named = "SVC_URL", matches = "http://.*")
void myTest() { /* no assumeTrue needed */ } Defensive patterns
Strategy: validation
Validate before calling
// Validate the precondition yourself and decide explicitly whether to skip
boolean preconditionMet = System.getenv("DB_URL") != null;
org.junit.jupiter.api.Assumptions.assumeTrue(preconditionMet, "requires DB_URL");
// Or use the declarative form instead of assumeTrue:
// @EnabledIfEnvironmentVariable(named = "DB_URL", matches = ".+") Try / catch
// Aborted tests are NOT failures — do not catch TestAbortedException in test code.
// Only catch it in custom extension/runner code:
try {
executable.execute();
} catch (org.opentest4j.TestAbortedException ignored) {
// expected skip; record and continue
} Prevention
- Prefer declarative @EnabledIfSystemProperty / @EnabledIfEnvironmentVariable over imperative assumeTrue for env-gated tests.
- Always pass a descriptive message so aborted tests are easy to triage in reports.
- Remember: assumption failure = skipped, not failed; do not 'fix' it by catching the exception.
When it happens
Trigger: Calling assumeTrue(false, "requires external service"), assumeFalse(true, "..."), assumeNotNull(nullRef, "..."), or assumeThat(...) with a non-matching condition, where the supplied message string/Supplier is non-blank. Also reached via assumeTrue(boolean, Supplier<String>) when the supplier returns a non-blank value.
Common situations: Tests gated on environment variables or system properties that are absent in CI (e.g., assumeTrue("CI".equals(System.getenv("ENV")), "integration test")), tests requiring a network service that is down, or platform-specific tests running on the wrong OS.
Related errors
- Assumption failed
- This class must not be instantiated
- Implement generateDisplayNameForNestedClass(List<Class<?>>,
- Implement generateDisplayNameForMethod(List<Class<?>>, Class
- This class must not be instantiated
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/5ef09f12edefa5a5.json.
Report an issue: GitHub.