Answer the question
In order to leave comments, you need to log in
How to catch exceptions in Spock (groovy)?
Let me explain the question. The framework offers us 2 types of execution blocks: when/then and expect/where.
In the first case, you have to duplicate the code; in the second, it is not clear how to catch exceptions. How to correctly build a test?
Answer the question
In order to leave comments, you need to log in
What does it mean to catch exceptions? If you check whether any exception was thrown during the test, then go to the documentation page and search for Exception Conditions on it - it is described there. In short, use the thrown() method. But there it is described only for when/then. If the code is duplicated, then what prevents you from putting it into a method and calling it later? Perhaps I did not understand the question and I need to be a little more specific and with an example.
spockframework.org/spock/docs/1.1-rc-4/all_in_one.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question