Skip to content

SoftAssertions should have forward() or rethrow() method #539

@Turbo87

Description

@Turbo87

My use case is the following: I have a folder with some files and would like to generate a unit test for every file. Since JUnit is not supporting anything like that I was thinking of using the SoftAssertions class instead. Unfortunately the test function itself is not under my control and uses JUnit assertions resulting in AssertionErrors.

I would like to catch those AssertionErrors and throw them again inside the SoftAssertions instance. I got two ideas for how this could work:

try {
    doTest(something);
} catch (AssertionError e) {
    softAssertions.rethrow(e);
}

of even simpler:

softAssertions.rethrow(() -> {
    doTest(something);
});

the only thing possible as of today looks like this:

try {
    doTest(something);
} catch (Throwable e) {
    softAssertions.assertThat(e).isNull();
}

but this is not printing the stacktrace or any other details of the caught exceptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions