Skip to content

Leave tests that call assumptions alone in TestsShouldIncludeAssertions - #1213

Merged
timtebeek merged 2 commits into
mainfrom
tim/tests-include-assertions-assumptions
Oct 24, 2026
Merged

timtebeek merged 2 commits into
mainfrom
tim/tests-include-assertions-assumptions

Conversation

@timtebeek

Copy link
Copy Markdown
Member

TestsShouldIncludeAssertions didn't treat assumptions as anything special, so a test guarded by an assumption but without an assertion got its body wrapped in assertDoesNotThrow:

@Test
void onLinux() {
    assertDoesNotThrow(() -> {
        assumeTrue(isLinux());
        service.start();
    });
}

assertDoesNotThrow catches the TestAbortedException a failed assumption throws, so a test that should have been skipped on other platforms now fails there.

The recipe now leaves a test unchanged when its body (or a helper it calls in the same class) calls JUnit Jupiter Assumptions, JUnit 4 Assume, or AssertJ Assumptions. The description mentions this too.

Fixes item C3 of #1211.

…ons`

A test such as `assumeTrue(isLinux()); service.start();` has no assertion, so the recipe wrapped its body in `assertDoesNotThrow(() -> {...})`. That catches the `TestAbortedException` thrown by a failed assumption and reports a test that should have been skipped as a failure. Calls to JUnit Jupiter `Assumptions`, JUnit 4 `Assume` and AssertJ `Assumptions` now make the recipe leave the test unchanged.
@timtebeek
timtebeek merged commit 2706beb into main Oct 24, 2026
2 checks passed
@timtebeek
timtebeek deleted the tim/tests-include-assertions-assumptions branch October 24, 2026 11:24
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant