Created
February 14, 2014 01:18
-
-
Save dyng/8993654 to your computer and use it in GitHub Desktop.
测试包含LWP::UserAgent的模块
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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