我正在尝试寻找是否可以在 Perl 测试文件中只运行一个测试用例。例如,考虑以下 Perl 测试文件(从 http://www.thegeekstuff.com/2013/02/perl-test-simple/ 复制):
#!/usr/bin/perl
use strict;
use warnings;
use Test::Simple tests => 2;
sub hello_world
{
return "Hello world!";
}
sub get_number
{
return int(rand(1000));
}
ok( hello_world( ) eq "Hello world!", "My Testcase 1" );
ok( get_number( ) > 0, "My Testcase 2" );
当我使用命令 prove -v test.t
运行此文件时,我得到以下输出:
test.t ..
1..2
ok 1 - My Testcase 1
ok 2 - My Testcase 2
ok
现在,我只想运行第二个测试用例,即 My Testcase2
。有没有办法在测试文件中只执行一个命名的测试用例?
最佳答案
简短的回答是:不,使用Test::Simple
(或Test::More
)提供的简单测试框架和证明
命令无法从测试脚本中挑出一个特定的断言并只运行该断言。
但是,Perl 测试生态系统提供了丰富多样的选项集。例如 Test::Class
允许您在标准测试协议(protocol)之上添加一个面向对象的层。这允许您将测试分组到方法中,添加设置和拆卸方法,以及 run individual test methods .如果不修改测试脚本,您仍然无法从命令行完成所有操作,但这离您的要求更近了一步。
当然,一个更简单的解决方案是将您想要的位复制到它自己的 .t
文件中并运行它。
关于perl - 在 Perl 测试文件中只运行一个命名的测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43502748/