Re: Mock HTTP servers for unit tests. [message #185670 is a reply to message #185669] |
Tue, 29 April 2014 20:24 |
Daniel Pitts
Messages: 68 Registered: May 2012
Karma:
|
Member |
|
|
On 4/29/14 11:51 AM, Jerry Stuckle wrote:
> On 4/29/2014 1:23 PM, Daniel Pitts wrote:
>> I'm developing some code which makes http requests from PHP. I'd like to
>> be able to Unit Test my code as smoothly as possible.
>>
>> I've searched Google, and I see there is more than one solution
>> available. I like the look of InterNations[1], but I wanted to ask this
>> community if they've had experience with any of them, and whether that
>> experience was positive or negative.
>>
>> Things I need:
>> * Ability to validate a specific request was made, with a specific
>> set of Headers.
>> * Ability to provide a "mock" response, and validate my code can
>> handle it.
>>
>> Things I really want:
>> * Ability to send parallel requests (think curl_multi), and validate
>> the requests are made in parallel.
>> * Ability to delay one response for a specific amount of time, but
>> have another response return earlier.
>>
>> Thanks,
>> Daniel.
>>
>> [1] https://github.com/InterNations/http-mock
>
> Daniel,
>
> Normally when testing, I test against the site the code is written for.
> If that's not possible (or I need further information than is supplied
> by the server, as you seem to need), I create my own test site and write
> server-side code to provide the appropriate information.
I'm talking about Unit Tests... I need to be able to run them while
offline, for instance. Integration tests would in theory be feasible
against a site. Note that I support multiple sites and I'm wanting to
unit-test some core functionality, not validate integration with any
other sites.
>
> You can see if the requests were made in parallel from the server logs.
> Other information can be validated by the pages being requested.
This doesn't solve my underlying problem. I want to write a Unit Test,
not an Integration Test. My Unit Test should take a few seconds at most
to run, and should not depend on an external service which may be
unavailable.
Thanks,
Daniel.
|
|
|