Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Seeking advice for testing a web service client

by xdg (Monsignor)
on Jan 10, 2007 at 05:01 UTC ( [id://593827]=perlquestion: print w/replies, xml ) Need Help??

xdg has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for suggestions for best practices for testing a web service client. For testing the service, there is Test::WWW::Mechanize and friends, but I want to write tests for the client.

I found Test::HTTP, which provides some handy test functions for HTTP responses, but it seems designed to do "live" testing against a service. For a service with an API key, though, I don't want to package automated tests with a key, or require users to supply one to Makefile.PL.

I suspect I should just use Test::MockObject to mock responses the client gets from calls to LWP.

All of this makes me think that writing tests for the client is going be harder and take longer than writing the client itself, so I'm looking for any suggestions or experiences that people can share for how to make it more painless.

Thanks in advance,

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

  • Comment on Seeking advice for testing a web service client

Replies are listed 'Best First'.
Re: Seeking advice for testing a web service client
by petdance (Parson) on Jan 10, 2007 at 06:09 UTC

      I'm not sure I understand how this improve on mocking/wrapping LWP::UserAgent::request(). I still need to inject the mock response to a request to HTTP::Server::Simple -- and this adds an extra layer of complexity. Is there some sample code you could point me to?

      HTTP::Server::Simple seems to be at the heart of many test failures on Win32, so I'm extra wary of using it if I don't have to. c.f. Vanilla Perl Problem Modules: Test::HTTP::Server::Simple, Test::WWW::Mechanize.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        For my tests of WWW::Mechanize::Shell, I wrote me Test::HTTP::LocalServer, which allows me to test simple interaction by providing canned responses and logging the incoming requests and outgoing responses. Depending on what you want to do, this might be sufficient for your needs, as all higher-level interaction can be faked by mocking LWP::UserAgent::request I guess.

Re: Seeking advice for testing a web service client
by shonorio (Hermit) on Jan 10, 2007 at 10:23 UTC
    I had problem with client that use AJAX/Javascript to enable bottom and things like that. Because this I had to change to write the test by hand with Mozilla::Mechanize, Win32::IE::Mechanize or SAMIE.

    Solli Moreira Honorio
    Sao Paulo - Brazil

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://593827]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found