grails - shouldFailWithCause fails test -
in grails 1.3.5 application have test method throws exception, test fails:
shouldfailwithcause(myexception) { vb.dostuff person }
the message is:
junit.framework.assertionfailederror: closure should have failed exception caused type myexception, instead found these exceptions: myexception: here comes message of exception.
it throws correct exception fails test. going wrong?
edit:
public void dostuff(person) { if (!canpersondostuff(person)) { throw new myexception("here comes message of exception") } }
shouldfailwithcause
looks cause
of exception instead of exception itself. can assertion work if add throw myexception
cause of exception.
public void dostuff(person) { if (!canpersondostuff(person)) { throw new exception(new myexception("the message of exception")) //or throw new exception(cause: new myexception("message")) } }
i rather use whatever logic have right in dostuff()
assert shouldfail{..}
instead of shouldfailwithcause{..}
because former checks exact exception thrown.
shouldfail(myexception) { vb.dostuff person }
Comments
Post a Comment