smeeb
smeeb

Reputation: 29527

Verify no exceptions were thrown in 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?

Upvotes: 44

Views: 18734

Answers (1)

tim_yates
tim_yates

Reputation: 171114

Found it.

You can use

noExceptionThrown()

To assert nothing was thrown

Upvotes: 91

Related Questions