szpak / blog.solidsoft.pl-comments

Comment storage for my technical blog - https://blog.solidsoft.pl
0 stars 0 forks source link

2020/03/18/places-where-you-really-need-to-use-assert-keyword-in-spock-assertions/ #7

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

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/

haridsv commented 2 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.

szpak commented 2 years ago

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".