Add Java keyword support for the assertion

  • Community Edition
  • Version 7.9.1 (build 27448)

assert should be listed in:

Hi Tomáš,

Do you know real project contexts where assert java keyword is used in tests?
Because I see assert equivalent to the assertTrue of JUnit, except it requires a specific JVM flag -enableassertions to do something. It seems error-prone to rely upon a specific configuration flag, to not have tests always green.

IMO, assert should only be used in the main source code (and not in tests).


Actually I do, but that’s incubating project about SOA and micro-services, where the tests are really simple as possible because of the Framework restrictions.
I definitely agree with the possibility to disable or enable assertions in the JVM, but I think this is the same argument as @Ignore any test.
Besides that Gradle is able change those values by default in <Test>.
However, we will ignore this error message, but I just wanted to share the strange behavior where frameworks are included, but the language keyword isn’t.

Thank you.

To me, an incubating test framework is not yet a good reason to change the rule behavior. I believe there are more non-java expert developers that could write in a test assert ... by mistake, than users of an incubating test framework where you can do it because of a specific test configuration.
So in your project context, I would recommend disabling this rule.
Unless you find an easy solution to provide to the rule S2699 an evidence that test can only be executed with the -enableassertions flags.