http://www.perlmonks.org?node_id=945127


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.