Test failing with the expected thrown exception #1350
-
I've run into a strange case that I can't sort out. We're testing a Spring service which calls a repository. The repository constructs a def "When Baz throws SQL exception"() {
given:
clob.getSubString(_, _) >> { throw new SQLException() }
def baz = new Baz(clob)
foo.bar(headerId) >> baz
when:
testSubject.doFoo(headerId)
then:
thrown(SQLException)
} As far as I can tell, the
What is going wrong here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @spartanhooah, this kind of question is more suited for Spock on Stackoverflow. However, you actually just gave the answer already.
And the stacktrace is the next hint:
So you don't see a reference to def "When Baz throws SQL exception"() {
given:
clob.getSubString(_, _) >> { throw new SQLException() }
when:
new Baz(clob)
then:
thrown(SQLException)
} |
Beta Was this translation helpful? Give feedback.
Hi @spartanhooah,
this kind of question is more suited for Spock on Stackoverflow.
However, you actually just gave the answer already.
And the stacktrace is the next hint:
So you don't see a reference to
testSubject.doFoo(headerId)
as it already fails in yourgiven
block when callingdef baz = new Baz(clob)
.As you didn't actually include a MCVE I can only guess if that fixes your problem. If you read the section about exception conditions