Yes, there is: the assert keyword should be enabled using the -ea flag, for example
java -ea MyClass
An assertion can be turned on and off without any changes to the code.
The Assert class will always work. So, if you are testing, use the Assert class, not the assert keyword. This may give you an idea that all your tests pass, and in fact they do not claim anything. In the 10 years of my coding, I have never seen anyone include statements other than Jetbrains, so use Assert instead. Or better, use Hamcrest .
Erik pragt
source share