Package Info

perl-Test-LWP-UserAgent


LWP::UserAgent suitable for simulating and testing network calls


Unspecified

This module is a subclass of LWP::UserAgent which overrides a few key low-level methods that are concerned with actually sending your request over the network, allowing an interception of that request and simulating a particular response. This greatly facilitates testing of networking client code where the server follows a known protocol.

The synopsis describes a typical case where you want to test how your application reacts to various responses from the server. This module will let you send back various responses depending on the request, without having to set up a real server to test against. This can be invaluable when you need to test edge cases or error conditions that are not normally returned from the server.

There are a lot of different ways you can set up the response mappings, and hook into this module; see the documentation for the individual interface methods.

You can use a PSGI app to handle the requests - see examples/call_psgi.t in this distribution, and also register_psgi below.

OR, you can route some or all requests through the network as normal, but still gain the hooks provided by this class to test what was sent and received:

my $useragent = Test::LWP::UserAgent->new(network_fallback => 1);

or:

$useragent->map_network_response(qr/real.network.host/);




is(
    $useragent->last_useragent->timeout,
    180,
    'timeout was overridden properly',
);
is(
    $useragent->last_http_request_sent->uri,
    'uri my code should have constructed',
);
is(
    $useragent->last_http_response_received->code,
    '200',
    'I should have gotten an OK response',
);

License: Artistic-1.0 OR GPL-1.0-or-later
URL: https://metacpan.org/release/Test-LWP-UserAgent

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
0.036-bp155.1.5 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-LWP-UserAgent
0.034-bp154.1.14 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-LWP-UserAgent
0.033-bp153.1.12 info GA Release 2021-03-06 15 SP3
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-LWP-UserAgent
0.033-bp152.3.15 info GA Release 2020-04-16 15 SP2
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-LWP-UserAgent
0.033-bp151.3.1 info GA Release 2019-07-16 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-LWP-UserAgent
0.033-bp151.2.12 info GA Release 2019-05-18 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-LWP-UserAgent
0.033-bp150.2.4 info GA Release 2018-07-30 15
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-LWP-UserAgent