Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 rifling through the Monastery: (7)
As of 2015-07-30 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls