Blog

Test::More で teardown/setup

http://blog.ainam.me/2013/04/09/test-more-perl-testing/ http://lestrrat.ldblog.jp/archives/26535307.html

package t::Util;
use parent qw(Exporter);
our @EXPORT = qw(lovetest $MOCK);
use Test::More;

sub lovetest {
  # setup
   local $MOCK = ...;
  # teardown は guard object で。
   goto \&Test::More::subtest;
}

そしてテストケースはこう。

lovetest 'foo' => sub {
  ...
  $MOCK->do_something;
};

というのがここ数年はブーム。

Test::Class も最近はだいぶ使いやすくなっているので、選択肢としてはありだとおもいます。