Perl 如何使用Test::Class::Load运行单个测试?

Perl 如何使用Test::Class::Load运行单个测试?,perl,unit-testing,Perl,Unit Testing,在积累了足够多的测试,运行这些测试都需要一些实时时间之后,我查看了,以找到运行单个测试类的技巧。它提供了一种实现这一点的方式,但我肯定错过了什么,因为我无法让它工作。以下是我所拥有的: 我的测试目录: drewfus:~/sandbox$ ls t/ lib/ perlcriticrc PerlCritic.t Unit.t t/Unit.t由以下部分组成: use strict; use warnings; use Test::Class; use Test::More 'no_pl

在积累了足够多的测试,运行这些测试都需要一些实时时间之后,我查看了,以找到运行单个测试类的技巧。它提供了一种实现这一点的方式,但我肯定错过了什么,因为我无法让它工作。以下是我所拥有的:

我的测试目录:

drewfus:~/sandbox$ ls t/
lib/  perlcriticrc  PerlCritic.t  Unit.t
t/Unit.t
由以下部分组成:

use strict;
use warnings;

use Test::Class;
use Test::More 'no_plan';
use Test::Class::Load 't/lib';
根据中的建议,我的每个测试类都有一个基类继承自,
SG::TestBase
,它位于
t/lib/SG/TestBase.pm

package SG::TestBase;
use strict;
use warnings;
use base 'Test::Class';

INIT { Test::Class->runtests }

1;
package SG::UtilsTest;
use strict;
use warnings;
use base 'SG::TestBase';

BEGIN { use_ok('SG::Utils') };
<etc>
最后,这里是一个示例测试类,
SG::UtilsTest
at
t/lib/SG/UtilsTest.pm

package SG::TestBase;
use strict;
use warnings;
use base 'Test::Class';

INIT { Test::Class->runtests }

1;
package SG::UtilsTest;
use strict;
use warnings;
use base 'SG::TestBase';

BEGIN { use_ok('SG::Utils') };
<etc>

祝贺您发现文档中的错误:-)

最后一个参数应该是测试类的路径,而不是包名。您还需要将路径添加到测试类库,以便prove可以发现它们正在执行以下操作:

  prove -lv -It/lib t/lib/SG/UtilsTest.pm

应该行得通。

这行得通,但七年后,文档仍然有相同的错误。