我有很多* .t文件,每个都有测试次数 我正在通过Test :: Harness执行所有* .t文件。 我如何编写单独的测试状态(通过/失败到数据库)
例如
use Test::More ;
use strict;
ok( $foo eq $bar, "TestCase1 " ) ? &subUpdateResult(pass) : &subUpdateResult(Fail) ;
ok( $1 eq $2, 'test case 2' );
ok( $3 eq $4, 'test case 3' );
sub subUpdateResult
{
#now a only dummy code I will update this code to connect DB later
my $val=sfift;
print "val is $val\n";
}
done_testing();
但我得到的结果如
ok 1 - TestCase1
ok 2
val is sfift
ok 3 - test case 2
ok 4 - test case 3
1..4
查询:为什么我在测试用例2之后得到打印结果?以及如何获得单独的测试状态,以便我可以更新数据库或写入Excel文件
答案 0 :(得分:1)
写shift
而不是sfift
。
给你错误的部分是
sub ok {
my($self, $test, $name) = @_;
# $test might contain an object which we don't want to accidentally
# store, so we turn it into a boolean.
$test = $test ? 1 : 0;
unless( $Have_Plan ) {
require Carp;
Carp::croak("You tried to run a test without a plan! Gotta have a plan.");
}
lock $Curr_Test;
$Curr_Test++;
$self->diag(<<ERR) if defined $name and $name =~ /^[\d\s]+$/;
You named your test '$name'. You shouldn't use numbers for your test names.
这是错误的来源,$name
参数不能只是数字和空格。您需要更正脚本的第3行,使用连接运算符。 (见:How do I interpolate a line number from __LINE__ into the name of a test in Perl?)
您的代码甚至编译得不好,我认为您提供的是不同的数据,以免将代码公开。我修改它如下,它的工作原理。你必须做类似的事情。另外,我不知道$1
和$2
的用途是什么?
#!/usr/local/bin/perl
use warnings;
use Test::More ;
use strict;
my $foo = "something";
my $bar = "something";
ok( $foo eq $bar, "TestCase1 " ) ? &subUpdateResult('pass') : &subUpdateResult('fail') ;
ok( $1 eq $2, 'test case 2' );
ok( $3 eq $4, 'test case 3' );
sub subUpdateResult
{
#now a only dummy code I will update this code to connect DB later
my $val=shift;
print "val is $val\n";
}
done_testing();