-
Hello, I am following along with this example adding picoCLI to an existing interactive shell. It has some existing Spock tests that look for expected thrown Exceptions in the business logic. I believe CommandLine::execute is swallowing the Exceptions, but I want to preserve my tests. After much digging, I think the best thing to do is implement DIY command execution. Since this is a shell, I wanted to know if there are any tips or pointers you can give that could save me some time e.g. is what I'm thinking even possible? (Also, If possible, it would be helpful to add a flag to allow Execution propagation or something along those lines for future users.) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The One idea is to have custom exception handlers: You could have a custom Alternatively you could do "black box" testing and inspect the Standard Error stream to see if a stack trace was printed, and if it contains the name of the expected exception class. |
Beta Was this translation helpful? Give feedback.
The
execute
method catches all exceptions, that is the intention.One idea is to have custom exception handlers:
Generally there are 2 types of errors: invalid user input and the application throwing an exception in its business logic.
There are separate
IParameterExceptionHandler
andIExecutionExceptionHandler
interfaces for these.You could have a custom
IExecutionExceptionHandler
that preserves the exception thrown by the business logic (in addition to printing a stack trace and returning a non-zero error code). The test code could then inspect whether the caught and preserved exception matches the expectation.Alternatively you could do "black box" testing and inspect the Standard Err…