Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3633256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:37:48+00:00 2026-05-19T00:37:48+00:00

I would like to do high level testing of my mochiweb app, like it

  • 0

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.

I refactored my code so that my requests handler would not call Req:respond() themselves, but return a tuple {Code, Headers, Body}. This allows me to build dummy requests with
mochiweb_request:new(), pass them to my request dispatcher and make assertions on the result using EUnit:

make_request(Method, Path) ->
    Request = mochiweb_request:new(nil, Method, Path, {1, 1},
        mochiweb_headers:make([{"Accept", "text/html"}])),
    Response = myapp:dispatch(Request),
    Response.


signin_test() ->
    {Code, _, _} = make_request('GET', "/signin"),
    ?assertEqual(Code, 200),
    ok.

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 Req:parse_post() is called, it triggers a read on a socket. I found some interesting test code in src/mochiweb.erl. 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 Req:parse_post() 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.

So what solution would you recommend to do functional or integration testing of a mochiweb app?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:37:48+00:00Added an answer on May 19, 2026 at 12:37 am

    i use the common test server and for testing i use ibrowse. Here is an example :

    post_cap_query_no_caps(_Config) ->
    A="<?xml version=\"1.0\" encoding=\"utf-8\"?><query><capabilities/></query>",
    {ok, "200", _C, Body}=ibrowse:send_req("http://localhost:8000/devices",  XML_CONTENT_TYPE, post, A),
    "<devices/>" == Body.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask a rather, general, high-level introductory kind of question regarding
I would like to render a control flow graph (CFG) out to high-level code.
I would like to know some low-level capabilities of high-level languages. Off the top
At very high level i would like to know apart from strings what (information)
I would like to hear from you folks that have achieved a high-level of
High level view of the application is: Form1 displays client information in a DataGridView
I have an automated integration test harness and would like to streamline the logging
I would like to write an app on Android to upload my GPS location
Would like to be able to set colors of headings and such, different font
Would like to know what a programmer should know to become a good at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.