František Žiačik
František Žiačik

Reputation: 7614

Spock interaction test takes precedence over exceptions

Why does the following test fail with "too few calls" instead of the actual exception that is thrown inside the do method before the mocked method could be called?

Is there any way to change this behavior?

@Test
def "Should Create"() {
    when: "We do stuff"
    this.someStuff.do()

    then: "Should not get exception"
    notThrown(Exception)

    and: "Should send mail"
    1 * mailSession.send(_, _, _, _, _, _, _)
}

Upvotes: 0

Views: 99

Answers (2)

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

You have discovered a bug. Please file an issue at http://issues.spockframework.org.

PS: Instead of notThrown(Exception), it's more common to use noExceptionThrown(). Instead of 1 * mailSession.send(_, _, _, _, _, _, _), it's more common to use 1 * mailSession.send(*_). @Test is a JUnit annotation that has no effect on Spock.

Upvotes: 2

topr
topr

Reputation: 4612

What is the exact type of exception thrown in do() method?

Possibly you may want to use noExceptionThrown() Spock method instead of notThrown(Exception).

Upvotes: 0

Related Questions