perl Testing(读书笔记(标注测试项目为TODO)

上一篇 / 下一篇  2012-04-07 21:57:20 / 个人分类:perl相关

 

如果某些被测试的项目还没有完成,但是测试驱动程序已经完成,那么久将这些还未完成的被测试项目在驱动程序中标注为TODO。测试报告会跟踪这些被测项目的状态,直到开发完成。

被测模块,File::Future,其中函数retrieve还未完成。

package File::Future;

use strict;

sub new {
 my ( $class, $filename ) = @_;
 bless { filename => $filename }, $class;
}

sub retrieve {
 # implement later...
}

1;

 

测试脚本如下:

#!/usr/bin/perl

use Test::More tests => 4;
use File::Future;

my $file = File::Future->new( 'perl_testing_dn.pod' );
isa_ok( $file, 'File::Future' );

TODO: {
 local $TODO = 'continuum not yet harnessed';
 
 ok( my $current = $file->retrieve( 'January 30, 2005' ) );
 ok( my $future  = $file->retrieve( 'January 30, 2070' ) );
 
 cmp_ok( length($current), '<', length($future), 'ensuring that we added text by 2070' );
}

运行结果如下:

D:\loveperl>perl future.pl
1..4
ok 1 - The object isa File::Future
not ok 2 # TODO continuum not yet harnessed
#   Failed (TODO) test at future.pl line 12.
not ok 3 # TODO continuum not yet harnessed
#   Failed (TODO) test at future.pl line 13.
not ok 4 - ensuring that we added text by 2070 # TODO continuum not yet harnesse
d
#   Failed (TODO) test 'ensuring that we added text by 2070'
#   at future.pl line 15.
#     '0'
#         <
#     '0'

其中的TODO确实失败了,但本来我们的期望就是如此,所以测试报告也是认为这也是测试成功的情况。

 

如果标注为TODO的测试项目确实通过了测试,这个测试会在报告当中说明这些意外获得成功的测试。

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar