On Thu, Sep 26, 2019 at 5:46 AM Marc Kaufmann <
marc.ka...@gmail.com> wrote:
>
> Thanks for clearing this up. If I understand correctly, the following happens:
>
> - the servlet raises an exception
> - this is caught by the default exception handler
> - it prints the traceback and exception message to standard output which I see (and which made me realize an exception had been raised), and it passes the response to the servlet-tester. However, the exception didn't bubble up to check-not-exn
>
> Since I can't turn off the exception handling of the servlets, I have to look at the output to find that an exception was thrown. Could I pass a different exception-handler to the test-servlet, which would return something easier (and more robust) to check whether an exception was thrown or not? Or should I bundle the servlet into a lambda for this, and have an exception-handler in that lambda that simply outputs "exception-raised" or some such? Otherwise I can of course parse the output, but that seems a little more error-prone.
I think you're thinking about this wrong. It is not that can't "turn
off the exception handling" or that "the exception didn't bubble up".
If you go to
pkgs.racket-lang.org and there's an exception in the code
on the server, do you expect the Racket exception to be thrown to
Google Chrome where a `with-handlers` can catch it? Of course not.
`make-servlet-tester` is literally a network client. It starts up a
hidden server and connects to it.
So, you need to ask what it is that you are trying to test...
If you want to know if a certain Racket function throws an exception,
then just test that function directly and use `check-not-exn`. That's
what Rackunit, chk, and other libraries are for. In this case, you are
testing a Racket function for its behavior: so you ask "Racket"
questions, like "Are exceptions thrown?".
If you want to know if your servlet returns certain pages, then use
`make-servlet-tester` to inspect the pages that get generated. In this
case, you are testing a Web app for its behavior: so you ask "Web"
questions, like "Is the background of the page purple?".
Jay