Spock throw exception test
I believe your then block needs to be fixed. Try the following syntax: then: thrown CustomException
I believe your then block needs to be fixed. Try the following syntax: then: thrown CustomException
The recommended solution is to have two methods: one that tests the good cases, and another that tests the bad cases. Then both methods can make use of data tables. Example: class SomeSpec extends Specification { class User { String userName } def ‘validate valid user'() { when: validateUser(user) then: noExceptionThrown() where: user << [ … Read more
Attention: I am going to oversimplify and maybe even slightly falsify in the upcoming paragraphs. For more detailed info see Martin Fowler’s website. A mock is a dummy class replacing a real one, returning something like null or 0 for each method call. You use a mock if you need a dummy instance of a … Read more