【发布时间】:2018-11-10 03:20:48
【问题描述】:
我有一组测试,总是命名为Module.t,每一个都是这样开始的:
use 5.026;
use strict;
use warnings;
use Test::Perl::Critic (-severity => 3);
use Module::Path 'module_path';
use Test::More tests => 8;
use Test::Log4perl;
Test::Log4perl->suppress_logging;
BEGIN { use_ok("My::Module") }
critic_ok(module_path("My::Module"));
... actual tests for this module ...
之所以这样做,是因为一堆模块的编码不是很好,并且为了在我们进行时重构东西,我正在尝试随着时间的推移为单个模块编写测试。例如。我不能只为所有来源启用 Perl::Critic,因为它会在我的脸上爆炸。
理想情况下,我希望为所有这些进行“父”测试,这样当我或其他开发人员想要编写新测试时,他们将始终拥有所有必需的东西。比如:
use 5.026;
use strict;
use warnings;
# 6 tests because 2 (use_ok and critic_ok) are already in the parent
use parent ParentTest("My::Module", tests => 6);
... actual tests for this module ...
perl 有办法做到这一点吗?
免责声明:我是 perl 菜鸟,所以也许这有更好的解决方案 :-)
【问题讨论】:
标签: perl unit-testing testing