sys::Test.verifyErr is great for testing that a specific Err is thrown, but I always find myself taking the test one step further and verifying the Msg in the Err. It's something I do in all my projects and as such, my test superclasses always has the following:
Void verifyErrMsg(Type errType, Str errMsg, |Test| c) {
try {
c.call(this)
} catch (Err e) {
if (!e.typeof.fits(errType))
verifyEq(errType, e.typeof)
verifyEq(errMsg, e.msg)
return
}
fail("$errType not thrown")
}
If others do similar then it may be worth considering adding it to Test.
Also, what of having a verifyTrue()??? I know I'm supposed to use verify() but given there's a verifyFalse() I always feel cheated that there's not a opposing verifyTrue()! I find myself typing it a lot, and then I have to correct it. Plus it looks strange nestled in-between the false statements:
I'm not saying delete verify(), just add a pseudonym for it. (I'm usually against having 2 differently name methods that do the same thing - but I can make an exception in this case!)
brianSun 22 Jun 2014
I really like verifyErrMsg - great idea.
I am not super keen on verifyTrue, but its only a line of code. So I don't have a big problem with it.
If you are interested in implementing send me the patch
SlimerDude Sun 22 Jun 2014
sys::Test.verifyErris great for testing that a specificErris thrown, but I always find myself taking the test one step further and verifying the Msg in the Err. It's something I do in all my projects and as such, my test superclasses always has the following:Void verifyErrMsg(Type errType, Str errMsg, |Test| c) { try { c.call(this) } catch (Err e) { if (!e.typeof.fits(errType)) verifyEq(errType, e.typeof) verifyEq(errMsg, e.msg) return } fail("$errType not thrown") }Typical usage in a test would be:
Void testMeltdown() { reactor := iocRegistry.serviceById("NuclearReactor") verifyErrMsg(DangerErr#, "Thermonuclear meltdown imminent") { reactor.shutdown() } }If others do similar then it may be worth considering adding it to
Test.Also, what of having a
verifyTrue()??? I know I'm supposed to useverify()but given there's averifyFalse()I always feel cheated that there's not a opposingverifyTrue()! I find myself typing it a lot, and then I have to correct it. Plus it looks strange nestled in-between the false statements:I'm not saying delete
verify(), just add a pseudonym for it. (I'm usually against having 2 differently name methods that do the same thing - but I can make an exception in this case!)brian Sun 22 Jun 2014
I really like verifyErrMsg - great idea.
I am not super keen on verifyTrue, but its only a line of code. So I don't have a big problem with it.
If you are interested in implementing send me the patch
SlimerDude Tue 24 Jun 2014
Okay, will do!