Assertj-core: Feature request : upgrade to junit 5

Created on 30 Dec 2017  路  12Comments  路  Source: assertj/assertj-core

Summary

Upgrade dependencies to junit 5.

As far as I know, it's only needed to support SoftAssertions rule.
I guess it implies changing almost all classes testing assertj itself, right ?

Java 8 specific ?

  • YES, since it's required by junit 5 => create Pull Request from the master branch

Most helpful comment

@mkobit just keep in mind that if JUnit 4 is on the classpath then it would use ComparisonFailure, as we don't know whether we are in a JUnit 4 or 5 test

All 12 comments

@fduminy except for JUnit rules, have you found any blockers to use the current AssertJ with JUnit 5?

I have used AssertJ extensively with JUnit 5 and not ran into any issues. The only thing I that might be useful would be to throw OTA4J types (from https://github.com/ota4j-team/opentest4j) instead of the java.lang.AssertionError. This might be better reflected in test reporting or IntelliJ but I really don't know.

AssertJ 2.9.0/3.9.0 should throw the opentest4j types (see e.g.: https://github.com/joel-costigliola/assertj-core/blob/cc178abc5871bc34525113550373ffd90e303034/src/main/java/org/assertj/core/error/ShouldBeEqual.java)

Thanks @PascalSchumacher I didn't see that mentioned in the change log and am only in the process of upgrading today, but that looks good!

@mkobit this is in the 2.9.0 release notes (improvements section), but I don't blame you not reading the fine prints, could be good new year resolution though :smile:

Hah maybe you should blame me. I searched the page for "ota" and not "opentest4j" 馃う.

I blame you @mkobit! :joy:

@mkobit just keep in mind that if JUnit 4 is on the classpath then it would use ComparisonFailure, as we don't know whether we are in a JUnit 4 or 5 test

Should throwing of opentest4j exceptions also work for custom assertions? Seems that this part is using some other technique. I have an assertion like the following:

    public IssueAssert hasDescription(final String description) {
        isNotNull();

        if (!Objects.equals(actual.getDescription(), description)) {
            failWithMessage(EXPECTED_BUT_WAS_MESSAGE, "description", actual, description, actual.getDescription());
        }
        return this;
    }

The failWithMessage code still throws an AssertionError.

@uhafner Sorry late comment but AssertionError is part of the JDK thus definitely something to keep using.

I'm closing this issue but feel free to comment it and I'll reopen it if needed.

It is ok to close this issue, since the actual problem is also described in https://github.com/joel-costigliola/assertj-assertions-generator/issues/90.

I just wonder why throwing exceptions in assertj-core is different than in the generated custom assertion classes. In assert-core, all messages are correctly parsed by IntelliJ , however, custom assertions do not provide this nice feature.

Was this page helpful?
0 / 5 - 0 ratings