“assert” keyword in Java and Groovy

Tymur Kubai
1 min readAug 2, 2019

--

Sometimes you discover “obvious things” too late.

I wrote auto-test on Java for more than 6 years.

I used TestNG, jUnit4/5 to write assertions. And I always think that assert keyword in Java missing error message.

There are not much help when you see Assertion Error in console. Only useful information is line of code where it fails.

In Groovy thou assert show you all callback from functions and variables value and you don’t need any additional assertion wrappers, but still you miss some business/human explanation of failure.

But recently I found out that you just can wrote error message, assertion syntax simple as hell.

assert (1 == 2) : "my custom error message";

And in the end you will get

java.lang.AssertionError: my custom error message

--

--

No responses yet