Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to test a mochiweb application?
    primarykey
    data
    text
    <p>I would like to do high level testing of my mochiweb app, like it is possible to do in Python with WebTest, in Django with the test client and in Ruby on Rails with functional or integration testing. I'm not too picky about how to do it. Basically I would just like to send or simulate HTTP requests and make assertions on the result. </p> <p>I refactored my code so that my requests handler would not call <code>Req:respond()</code> themselves, but return a tuple <code>{Code, Headers, Body}</code>. This allows me to build dummy requests with <code>mochiweb_request:new()</code>, pass them to my request dispatcher and make assertions on the result using EUnit:</p> <pre><code>make_request(Method, Path) -&gt; Request = mochiweb_request:new(nil, Method, Path, {1, 1}, mochiweb_headers:make([{"Accept", "text/html"}])), Response = myapp:dispatch(Request), Response. signin_test() -&gt; {Code, _, _} = make_request('GET', "/signin"), ?assertEqual(Code, 200), ok. </code></pre> <p>Now my problem is how to test POST requests. I didn't find anything in mochiweb that would allow me to do that. From reading mochiweb code, it seems that when <code>Req:parse_post()</code> is called, it triggers a read on a socket. I found some interesting test code in <a href="https://github.com/mochi/mochiweb/blob/master/src/mochiweb.erl#L95" rel="nofollow">src/mochiweb.erl</a>. Apparently this involves building HTTP messages, writing them on a socket and reading the response back. I tried to do this in my own test code but I didn't manage to get anywhere after a few hours. I'm beginning to wonder if I'm going in the right direction. Maybe I need to decouple even more my functionality from the HTTP plumbing, ie. not call <code>Req:parse_post()</code> from within my request handlers. Another solution I'm thinking of would be to use a third-party web testing library, not necessary written in Erlang. Maybe something in Ruby or Python or even maybe Selenium.</p> <p>So what solution would you recommend to do functional or integration testing of a mochiweb app?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload