neo's profile十年一场梦 ..BlogListsGuestbookMore Tools Help

Blog


    11/18/2009

    PERL TESTING 2

     
    检查test覆盖率
    先安装 Devel::Cover
    cover -delete
    HARNESS_PERL_SWITCHES=-MDevel::Cover make test
    cover
       (需要修改Makefile.PL 以使make test可正常运行, 参考下其他模块的Makefile.PL怎么写的 )
     

    编写测试库, 扩展自己的测试函数 比如 is_between    
    package Test::Between             
    use base 'Exporter';
    out @EXPORT=qw(is_between);   //导出is_between
    use Test::Builder;
    my $Test=Test::Builder->new();
    sub is_between($$$){
     ...
     $Test->ok(...) or $Test->diag("..");
    }
     

    测试库的测试...
    use xxx;
    use Test::Builder::Tester tests=>n;
    test_out("ok1 xxxx");      //预期要收到的消息
    is_xxx;
    test_test();  //比较测试输出的信息是否与之前给定的信息相同
     
    test_out("not ok1 xxx");
    test_fail(+2);    //下面第2行会测试错误
    test_diag("xxx")   //错误提示
    is_xxx;
    test_test()
     

    编写测试解析  扩展TAP
    use Test::Harness::Straps;
    my $strap=Test::Harness::Straps->new();
    for my $file(@ARGV){
     my %r=$strap->analyze_file($file);
     printf <<END,$file,@r(qw(max ok skip ...));     //max..等可自己选择 参看帮助
    Results for %s
    Expected tests :%d
    pass: %d
    ...
    END
    }
     

    测试pod文件
    use Test::Pod;
    all_pod_files_ok();
     
     
    测试pod覆盖率
    use Test::Pod::Coverage;
    all_pod_coverage_ok();
     
     
    测试整个模块--依赖性 版本号 pod... 
    use Test::Distribution;
    Test::Distribution->import();
    在Makefile.PL或Build.PL加入用户提示,由用户选择测试集
    1)makefile
    use ExtUtils::MakeMaker;
    my %config=(
    ..
    );
    my @p=qw(t/*.t);
    my $answer=prompt('xxx');
    if($answer=~/y/i){
     push @p,'t/long/*.t';
    }
    $config{test}={TESTS=>join ' ', map {glob} @p};
    WriteMakefile(%config);

    2)build
    use Module::Build;
    my $answer=Module::Build->y_n(‘xxx’);
    if($answer){
    ...
    }
    my $builder=Module::Build->new(
    ...
    test_files=>$p,
    );
    $builder->create_build_script();
     
     
    建立模块缺省初始目录
    安Module::Starter
    module-starter --mb --distro=xxx --author=xxx --email=xxx --verbose
     
     
    自动生成测试报告
    修改Build.PL
    use Module::Build::TestReporter;
    my $build=Module::Build::TestReporter->new(
    ...
    report_file=> 'xx',
    report_address=>'xx',
    );
    $build->create_build_script();
     
     
    确保技量
    require Test::Kwalitee;
    Test::Kwalitee->import();

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://sh-neo.spaces.live.com/blog/cns!1E3CA285E5F9E122!766.trak
    Weblogs that reference this entry
    • None