I just found a case where I want to check that something throws an error AND
that it doesn't affect the results. For example, let's say I have a function
that slaps three numbers onto the end of a list, but only if they're in order,
and if they're not in order, it shouldn't add any on, not even ones that come
before the first that's out of order.
But I don't want only to check that an error is thrown; I also want to make
sure that the implementation didn't add 120 to the list before it realized
that 15 was out of order.
Is there a way to do this? Check both that an error is thrown, and that some
condition is true afterwards?
Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Instead of using Assert.Throws in this scenario you could trap the error
yourself and handle additional assertions.
On Error Goto errTrap
blah.putNumbers 120, 15, 140
Assert.Fail "An error should be raised."
errTrap:
Assert.That Err.Number, Iz.EqualTo(E_FAIL), "Wrong error number raised."
' add additional asserts to check the state of blah.
Assert.Pass
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just found a case where I want to check that something throws an error AND
that it doesn't affect the results. For example, let's say I have a function
that slaps three numbers onto the end of a list, but only if they're in order,
and if they're not in order, it shouldn't add any on, not even ones that come
before the first that's out of order.
For example (pseudocode):
But I don't want only to check that an error is thrown; I also want to make
sure that the implementation didn't add 120 to the list before it realized
that 15 was out of order.
Is there a way to do this? Check both that an error is thrown, and that some
condition is true afterwards?
Thanks in advance.
Instead of using Assert.Throws in this scenario you could trap the error
yourself and handle additional assertions.
Thanks!