Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Testing error handling that calls "die"

by TomDLux (Vicar)
on Dec 26, 2011 at 19:59 UTC ( #945127=note: print w/ replies, xml ) Need Help??


in reply to Testing error handling that calls "die"

Ovid's 3-part article on Test::Class at the Modern Perl website taught me the basics of testing exceptions:

That should be pretty clear. Look at the new test now. Use the th +rows_ok test from Test::Exception to test the Carp::croak(). Using Test:: +Most instead of Test::More makes this test function available without +explicitly using Test::Exception. sub full_name : Tests(no_plan) { my $test = shift; my $person = $test->class->new; can_ok $person, 'full_name'; throws_ok { $person->full_name } qr/^Both first and last names must be set/, '... and full_name() should croak() if the either name is + not set';

Don't forget the first arg to throws_ok is a code block or anon subroutine

As Occam said: Entia non sunt multiplicanda praeter necessitatem.


Comment on Re: Testing error handling that calls "die"
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://945127]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-12-29 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls