Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Test::Exception

  • Test::Exception

Test::Exception.

use strict;
use warnings;

use Test::More;
use Test::Exception;

use MyTools qw(fibo);

is fibo(6), 8, 'fibo(6)';

throws_ok { fibo() } qr/Need to get a parameter/, 'missing parameter';
throws_ok { fibo('name') } qr/Need to get a number/, 'not a number';

done_testing;
1..2
ok 1 - div by 2
ok 2 - div by zero
throws_ok { $foo->method } 'Error::Simple', 'simple error thrown';

Where Error::Simple is the class of the exception that have been thrown. e.g. by Exception::Class.