neo's profile十年一场梦 ..BlogListsGuestbookMore ![]() | Help |
|
|
11/18/2009 PERL TESTING 1use Test::More tests=>n 测试 计划
use Test::Simple
ok(xxx() eq "xxx",'information'); use Test::More
use_ok('module xx', qw(function1 function2)); 测试模块是否加载 can_ok('module xx','function1'); 测试该模块是否包含function1函数
isa_ok($i,'class') 测试该类对象构造器是否返回了正确无误的‘class’对象
is( 1,2,'xx') 与ok类似 两个参数对比, 第二个参数为期望值,第三个参数为描述信息
like(1,2,'xx') 同上,但2为正则表达式
跳过某些测试
SKIP:{ eval 'xxx'; skip('infor..',1) if $@; 如果eval捕获到错误 将skip testxxx testxxx... } 跳过所有测试
if(){ plan(skip_all=>'infor...'); }else{ plan(tests=>n); } .... .... 标记为TODO
TODO:{ local $TODO ='info..'; testxxx... } 测试比较 is_deeply($1,$2,'info..') 测试$1 $2是否相等
use Test::Differences eq_or_diff($1,$2,'info..') 类似diff use Test::LongString
is_string($1,$2,'info..') 测试超长字符串 测试复杂数据结构
use Test::Deep; my $s=re('正则'); cmp_deeply($p,array_each( { x=>$s, y=>$s, z=>ignore(), z变量值不确定 可忽略 } ),'info..'); 对$p内部 每个变量都进行正则匹配 array_each( superhashof( 可测试极小集 其他变量也可出现 {...} ) ) array_each(
subhashof( 极大集 {} ) ) 测试中数据顺序不确定 @b为预期值
@a=(4,89,2,7,1); @b=(1,2,7,4,89); cmp_bag(\@a,\@b) 测试警告
use Test::Warn warning_is{ add(8,-3)} " xxx" add函数当参数为-数时会报告警告xxx 这里的xxx为期望值 我门这是测看他是否能正确报警告 warning_are{add(-8,-3)} ['xxx','xxx'] warning_like{add(-8,3)} [ar/正则/] use Test::NoWarnings
is(add(2,3),5) 测试正常情况不报警告 测试异常
use Test::Exception use Error throws_ok {add(-5,2)} 'Error::Simple' 测试是否正确抛出异常 类型为'Error::Simple' lives_ok {add(5,2)} 'no execption here!' 测试正确情况下是否不抛出异常 TrackbacksThe trackback URL for this entry is: http://sh-neo.spaces.live.com/blog/cns!1E3CA285E5F9E122!765.trak Weblogs that reference this entry
|
|
|