The output of `make-servlet-tester` returns the HTTP response object that the servlet returns. `make-servlet-tester` really makes a HTTP connection to your servlet and is checking the actual result that you sent back. If the servlet throws an exception, then probably you have the default exception handler which turns that into an HTML display. That HTML display would be returned and thus, there was no exception. In other words, it is not a sufficient test of what you want to check that no exception is thrown, you want to make sure a desirable page is returned.
Jay -- Jay McCarthy Associate Professor @ CS @ UMass Lowell http://jeapostrophe.github.io Vincit qui se vincit. On Tue, Sep 24, 2019 at 9:34 AM Marc Kaufmann <marc.kaufman...@gmail.com> wrote: > Hi all, > > I have gone through https://docs.racket-lang.org/web-server/test.html to > finally stop manually checking whether I didn't introduce new bugs in one > of my servlets. I think that I have figured out most of the wrinkles for > this, except one. > > I run my tests via `raco test server.rkt`, and server.rkt has the > following structure: > > (require web-server/test web-server/servlet ...) > > (define (start request) > (define-values (top-dispatch top-urls) > (dispatch-rules > [("") home] > [("login") #:method (or "post" "get") log-in] > [("mp") #:method (or "post" "get") mp] > ... > )) > > (top-dispatch request)) > > (module+ main > (serve/servlet start ...)) > > (module+ test > > (define (test-start-servlet) > > (define experiment-servlet-tester > (make-servlet-tester start)) > > ; Test all the routes. This only tests that they don't raise exceptions > (define routes > (list > '() ; Tests "/" > '("/login") > '("/mp") > )) > > (for ([route routes]) > (check-not-exn (λ () (apply experiment-servlet-tester route)))) > > (define matrix-servlet-tester > (make-servlet-tester (λ (req) > (matrix req #:h (hash 'mturk-id "TESTER"))))) > > (matrix-servlet-tester) > > (displayln "All pages render without exception")) > > (test-start-servlet)) > > > The meat of what is going on is in the test module at the end. I create a > servlet-tester for the start servlet, which uses a dispatcher, and since I > have a bunch of routes I go through them in a for-loop. However, even > though the "/login" route throws an exception, the (test-start-servlet) > code is happily marching on, checks the "/mp" route, and then prints "All > pages render without exception". And raco test tells me that all the tests > are passing! > > How do I know that there is an exn? Because it prints the following right > before the test results: > > Servlet (@ /372d34a3-df04-478f-8d84-94fb212725c2) exception: > >: contract violation > expected: real? > given: #<sql-null> > argument position: 1st > other arguments...: > 0 > > > So, what is going on here? Clearly test-servet does some exception > catching in between, yet it still prints it to the screen? How can I test > for this, since I want to know how many and which pages blow up? > > Also, when I want to test matrix at the end, I have to pass it an extra > argument. Is it the right way of passing in the argument by defining a new > servlet where I set the argument to some fixed value, as I do above via: > > (define matrix-servlet-tester > (make-servlet-tester (λ (req) > (matrix req #:h (hash 'mturk-id "TESTER"))))) > > It seems to work, but I am wondering if I can pass arguments directly to > `make-servlet-tester`, but I couldn't figure out how. > > Thanks, > Marc > > -- > 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/a7ae5893-5bdd-4b3f-924a-42e4936d2a68%40googlegroups.com > <https://groups.google.com/d/msgid/racket-users/a7ae5893-5bdd-4b3f-924a-42e4936d2a68%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAJYbDane6RA8pZpf65NnFO5tgyPRowSE1ggt5KD8cGNW1kP0NQ%40mail.gmail.com.