Skip to content

Instantly share code, notes, and snippets.

@dyng
Created February 14, 2014 01:18
Show Gist options
  • Save dyng/8993654 to your computer and use it in GitHub Desktop.
Save dyng/8993654 to your computer and use it in GitHub Desktop.
测试包含LWP::UserAgent的模块
use Test::More;
use Test::MockModule;
use HTTP::Request;
our $request_count = 0;
my $mock_ua = Test::MockModule->new('LWP::UserAgent');
$mock_ua->mock('request', sub {
$request_count++;
HTTP::Response->new(200);
});
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => 'http://www.example.com/');
$ua->request($req);
is $request_count, 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment