A.H
A.H

Reputation: 23

Testng assertj report and continue

I'm using AssertJ to test web using fluentlenium and extent reports for reporting the results.

I asked before the question but forgot to mention the use of AssertJ.

The provided answer was to extend soft assert and that it has onAssertFailure function.

Is there anything like this for AssertJ soft assertions? Or is there another solution to bypass it?

Upvotes: 2

Views: 713

Answers (2)

Joel Costigliola
Joel Costigliola

Reputation: 7116

In the next AssertJ version (2.5.0) you will have access to all soft assertions errors (see this commit).

Hope it helps

Upvotes: 3

Mobrockers
Mobrockers

Reputation: 2148

In a future release of assertJ a method wasSuccess() is added (as can be seen on git history), but it is not yet available in the current release.

When this method is added you can do something like this:

public class AssertjSoftAssert extends SoftAssertions {

    private void checkFailure() {

        if(!wasSuccess()) {

            onFailure();
        }
    }

    private void onFailure() {

        //doFailureStuff
    }

    @Override
    public BigDecimalAssert assertThat(BigDecimal actual) {

        BigDecimalAssert assertion = super.assertThat(actual);
        checkFailure();
        return assertion;
    }

    @Override
    public BooleanAssert assertThat(boolean actual) {

        BooleanAssert assertion = super.assertThat(actual);
        checkFailure();
        return assertion;
    }
}

Do note, however, that you will have to override EVERY assertion method in the SoftAssertions class like I've shown you with the examples here. And also if new Assertions are added to the SoftAssertions class you will have to override those as well. This is the best solution I could find right now, but won't work until assertj is updated either.

EDIT: Actually I am not sure this would even work because I am not sure wasSuccess() will return true after every successvul softassert or only after throwing assertAll() but I can't test this obviously as the feature isn't out yet.

Bonus: The commit that added wasSuccess()

Upvotes: 1

Related Questions