{"id":"5ef09f12edefa5a5","repo":"junit-team/junit5","slug":"assumption-failed","errorCode":null,"errorMessage":"Assumption failed: ","messagePattern":"Assumption failed: ","errorType":"exception","errorClass":"TestAbortedException","httpStatus":null,"severity":"info","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assumptions.java","lineNumber":339,"sourceCode":"\t *\n\t * <p>See Javadoc for {@link #abort(String)} for an explanation of this\n\t * method's generic return type {@code V}.\n\t *\n\t * @param messageSupplier the supplier of the message to be included in the\n\t * {@code TestAbortedException}\n\t * @throws TestAbortedException always\n\t * @since 5.9\n\t */\n\t@Contract(\"_ -> fail\")\n\t@API(status = STABLE, since = \"5.9\")\n\t@SuppressWarnings(\"TypeParameterUnusedInFormals\")\n\tpublic static <V> V abort(Supplier<String> messageSupplier) {\n\t\tthrow new TestAbortedException(messageSupplier.get());\n\t}\n\n\t@Contract(\"_ -> fail\")\n\tprivate static void throwAssumptionFailed(@Nullable String message) {\n\t\tthrow new TestAbortedException(\n\t\t\tStringUtils.isNotBlank(message) ? \"Assumption failed: \" + message : \"Assumption failed\");\n\t}\n\n}\n","sourceCodeStart":321,"sourceCodeEnd":344,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assumptions.java#L321-L344","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nassumeTrue(\"http://svc\".equals(System.getenv(\"SVC_URL\")), \"requires SVC_URL\");\n\n// after — set the env var, or guard the whole test:\n@EnabledIfEnvironmentVariable(named = \"SVC_URL\", matches = \"http://.*\")\nvoid myTest() { /* no assumeTrue needed */ }","handlingStrategy":"validation","validationCode":"// Validate the precondition yourself and decide explicitly whether to skip\nboolean preconditionMet = System.getenv(\"DB_URL\") != null;\norg.junit.jupiter.api.Assumptions.assumeTrue(preconditionMet, \"requires DB_URL\");\n// Or use the declarative form instead of assumeTrue:\n// @EnabledIfEnvironmentVariable(named = \"DB_URL\", matches = \".+\")","typeGuard":null,"tryCatchPattern":"// Aborted tests are NOT failures — do not catch TestAbortedException in test code.\n// Only catch it in custom extension/runner code:\ntry {\n    executable.execute();\n} catch (org.opentest4j.TestAbortedException ignored) {\n    // expected skip; record and continue\n}","preventionTips":["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."],"tags":["assumption","conditional-test-execution","test-aborted","junit-jupiter"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}