How can I set the expectancy of an exception to be thrown in a test in Clojure?
Thanks in advance!
If a method under test declares an exception in its signature, then the test method can allow the exception to propagate to the ABAP Unit runtime. It is best that the test method declares the exception so that the possible behavior of the method is clear. The test method should not catch the exception. .
You can add exception in test method signature. Then, if you are testing whether exception is thrown, you have to use @Test(expected=Exception. class) . In the test cases where exception has not to be thrown, test will pass successfully.
This answer addresses the try/catch part of your question only. If an exception is thrown from the code being tested (or the test code) then the test is a fail and that is normally what you want to happen. and as not all exceptions are catchable (e.g. governor limit ones) it will not even always execute.
Exceptions are an integral part of the application. We understood that Unit test cases should be written for validated Technical or Business exceptions. Unit test cases for exceptions should improve the stability and robustness of your application.
(is (thrown? NumberFormatException (Integer/parseInt "49FREN")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With