Open utterances-bot opened 4 years ago
Good article and subject, but you could convey the message better by saying where asserts are not required instead of indicating all the places you would need them, because as I can see from the article, you missed a few. The official documentation clearly states this:
Conditions are an essential ingredient of then blocks and expect blocks. Except for calls to void methods and expressions classified as interactions, all top-level expressions in these blocks are implicitly treated as conditions. To use conditions in other places, you need to designate them with Groovy’s assert keyword
This is why the condition in given:
block, in method execution and in closure
needed explicit assert
. The other obvious places are if
blocks, loops and catch
blocks.
Thanks @haridsv for taking time to made that constructive comment!
You are completely right. I've just added a new section covering the "other cases".
Places where you REALLY NEED to use 'assert' keyword in Spock assertions | Solid Soft
Make sure you know all the places where putting the 'assert' keyword in Spock is necessary to avoid false sense of security and tests which - effectively - do nothing.
https://blog.solidsoft.pl/2020/03/18/places-where-you-really-need-to-use-assert-keyword-in-spock-assertions/