Ah yes, that's right. I did somehow (without really thinking about it,
admittedly) think that the exception would get returned with the response.
I did not realize that test-servlet sets up a server.

So for testing the functions, I just create the right requests and do a
check-* test. That should also work to see if dispatch-rules calls the
correct routes, right? Or does that require something from a running server
that I don't realize?

I'll probably need some time before I figure out which type of testing
belongs where, hopefully I'll get to it this weekend.

On Thu, Sep 26, 2019 at 1:22 PM Jay McCarthy <jay.mccar...@gmail.com> wrote:

> On Thu, Sep 26, 2019 at 5:46 AM Marc Kaufmann <marc.kaufman...@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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAD7_NO5FYHcx-z0PVV2Nz7k%3DuRYrTUar5Fb3cDs657cJDWxa%3Dg%40mail.gmail.com.

Reply via email to