Dealing with errors
Dealing with errors that occur in a test is always a tricky subject. At the very least you want to report the error. Sometimes you also want to do some processing to recover or do some clean up.
All Simon’s the macros throw exceptions if they encounter a problem. Simon automatically catches these and reports on them in it’s final report. Simon also makes use of a hierarchy of custom exceptions so that you can readily identify what went wrong. Here’s the list:
Simon will also pick up on any other exceptions that are thrown. So the best way to get something reported on is to throw an exception.
Apple error processing recommendations
If you look at Apple’s error processing recommendations you will see that Apple recommends using NSErrors and error processing where ever possible rather than exceptions. Simon uses exceptions for dealing with tests because it can then catch a wider range of problems and it makes the code a lot simpler. Internally though Simon, uses NSErrors rather than exception where ever it can. This helps to separate internal error processing from test code errors.
So now lets take a look at a simple piece of code illustrating how this can be done:
Here we show several points of interest. The first is the catch for the SISyntaxException. Honestly it’s unlikely that you would want to catch this, but it’s a good illustration of how you could catch an exception. Just be sure to re-throw the exception so that Simon knows there was a problem. Also notice the @finally block which is an idea place for putting any clean up code you might want to run.
IndexSimon What is BDD? Why Simon?
Installation Quick Start Guide Simon's UI
Writing Stories Mapping Stories Step Conversations Validating Results Accessing your app's UI Exceptions and Errors
Macro reference API reference Simon's CLI args Pieman's CLI args Change Log Thank you BSD License