Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify no exceptions were thrown in Spock

Tags:

groovy

spock

I am brand new to Spock and perused their online docs. I have a test case where I need to verify that my fixture's interaction with a non-mock collaborator does not produce an exception:

class FizzSpec extends Specification {     def "no exception thrown when we hail buzz"() {         given:         Fizz fixture = new Fizz()         Buzz buzz = new Buzz("YES", true, "Garble barb") // A non-mock!          when:         fixture.hail(buzz)          // TODO: How to verify the hail didn't produce an exception?         // then:         // thrown() == null     } } 

Any ideas as to how I can accomplish this?

like image 530
smeeb Avatar asked Aug 20 '15 19:08

smeeb


1 Answers

Found it.

You can use

noExceptionThrown() 

To assert nothing was thrown

like image 121
tim_yates Avatar answered Sep 17 '22 12:09

tim_yates