Writing tests means formulating assumptions by using assertions. In Java this can be done
by using the assert keyword. But Groovy comes with a powerful variant of assert also
known as power assertion statement.
Groovy’s power assert differs from the Java version in its output given the boolean
expression validates to false :
def x = 1
assert x == 2
// Output:
//
// Assertion failed:
// assert x == 2
// | |
// 1 false
This section shows the std-err output
The java.lang.AssertionError that is thrown whenever the assertion can not be
validated successfully, contains an extended version of the original exception message.
The power assertion output shows evaluation results from the outer to the inner expression.
The power assertion statements true power unleashes in complex Boolean statements, or
statements with collections or other toString -enabled classes:
def x = [1,2,3,4,5]
assert (x << 6) == [6,7,8,9,10]
// Output:
//
// Assertion failed:
// assert (x << 6) == [6,7,8,9,10]
// | | |
// | | false
// | [1, 2, 3, 4, 5, 6]
// [1, 2, 3, 4, 5, 6]