use Test::More tests => 2; use Test::MockModule; my $obj = MyModule->new(); # Test the login method { my $lwp = Test::MockModule->new( 'LWP::UserAgent' ); $lwp->mock( request => sub { # Return a hand crafted HTTP::Response object my $response = HTTP::Response->new; $response->code(200); $response->content('Login Successfull'); return $response; }); my $code = $obj->login(); ok($code == 200, 'login'); } # Test the get_info method { my $lwp = Test::MockModule->new( 'LWP::UserAgent' ); $lwp->mock( request => sub { # Return a hand crafted HTTP::Response object my $response = HTTP::Response->new; $response->code(302); $response->content('Some Info'); return $response; }); my $code = $obj->get_info(); ok($code == 302, 'get_info'); }