John Jiang
John Jiang

Reputation: 11519

Enforce assertj in java tests

I would like to enforce assertj assertions instead of junit assertions in my tests. What's the best way? Alternatively, if I could prevent junit assertions that would be fine too.

Is there a way to do this via checkstyle?

Upvotes: 1

Views: 434

Answers (1)

rveach
rveach

Reputation: 2201

There are a few checks that can help you out. The best thing to do is to configure as many checks as you can because 1 may not catch everything.

The following checks can report violations when a user uses an improper import that you specify (junit).
Illegal Import - http://checkstyle.sourceforge.net/config_imports.html#IllegalImport - This bans specific imports that you specify.
Import Control - http://checkstyle.sourceforge.net/config_imports.html#ImportControl - This controls what imports are allowed and what are disallowed for your application. This allows customization for specific packages and classes over the other check.

The following can be used to report violations on any code you can write an expression for that the other checks didn't catch. Like if the user wrote out the full path instead of using an import. There is no check in checkstyle to do this currently.
Regexp Singleline - http://checkstyle.sourceforge.net/config_regexp.html#RegexpSingleline

Upvotes: 1

Related Questions