Spock throw exception test
If you would like to evaluate for instance the message on the thrown Exception, you could do something like:
then:
def e = thrown(CustomException)
e.message == "Some Message"
There could be multiple ways to handle the exception in then:
thrown(CustomException)
or
thrown CustomException
As well we can check if no Exception is thrown in the Test case -
then:
noExceptionThrown()
I believe your then
block needs to be fixed. Try the following syntax:
then:
thrown CustomException