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

Oh wise ones, forgive me for I have lost the light.

I am in the process of building a module for a webservice API. Think something simple, that works via SOAP and the input is A, and returns a job id. When the job is complete, you can poll it and it returns the data results.

What is the best way to build tests for something like this? In the past I have seen people writing tests which use the actual service which is online. Is this good practice? I would think not since the tests may fail for one reason on the other and be misleading. Would the best way be to mock a return from the service or so? I want to get it right this time so your help would be appreciate it. thank you for your help, Spiros

Replies are listed 'Best First'.
Re: webservice API testing
by Unforgiven (Hermit) on Jun 24, 2009 at 19:50 UTC
    Your description is a little vague, but would something like Test::MockObject help solve your problem? If you're using it in a way in which the API is represented by an object or objects, something like this might let you test the rest of your program without having to actually use the API.
      Hm, well what i was getting at is: how can i mock something that is supposed to be coming over the network, in this case, the results from the webservice. I want to do this in a clean and modular way.
Re: webservice API testing
by Your Mother (Archbishop) on Jun 24, 2009 at 20:19 UTC

    Take a look at this and search around in there for more maybe: Test::HTTP::Server::Simple. There are quite a few little standalone servers which can run tests locally/safely.

Re: webservice API testing
by stonecolddevin (Parson) on Jun 25, 2009 at 07:46 UTC

    In theory, you send a request, and get something back, webservice or any other service, right?

    So unless you need to test something in transit, I would think that something like Test::WWW::Mechanize would do quite well.

    meh.