Since : I always work for my future.
And : Linux is the future.
So: I work for Linux
网页自动测试 7. 从局部再回到整体
上一篇 /
下一篇 2008-06-06 07:44:16
/ 个人分类:automation
每一个独立的
测试程序都必须反复的调试,直到确认在正确的环境测试和提供正确的数据的情况下运行无误--也就是说,我们QA写的程序同样是程序,也需要经过测试和调整。虽然在某些方面和开发人员的程序有不一样的地方,但是基本的原理不应该有任何的差别。
调试我所有的程序花费了我不少的时间,在时间比较紧张的情况下,有些地方我就没有修复,仅仅是在程序里面留下一些说明,准备下次改正。
自动化测试当然是指在短时间里面测试一系列的功能,所以在单个测试程序完成和调试之后,我还需要些一个调用这些测试程序的程序。这个程序需要有如下的功能
1。自动调用单个测试程序
2。检查测试程序的执行结果,并记录
3。在所有调用的程序完成之后,打印测试报告。
完成了这些,才能说完成了部分的自动化测试--也就是说我们还有很多的
工作要做。
这个是它的一次执行结果:
$> ./exetestplan.pl showcase.testplan /tmp/testplan.log
Using test plan file [showcase.testplan] Loading test plan file... Load admin_principal_add_rpc.t Load admin_principal_add_snmp.t Load admin_policy_default_ui.t Load admin_add_group.t Load admin_edit_group_active-inactive.t Load admin_edit_group_addgroupmember.t Load admin_edit_group_cancle_editing.t Load admin_edit_group_delete.t Load admin_edit_group_descrīption.t Load admin_edit_group_gid.t Load admin_edit_group_name.t Load admin_edit_group_removegroupmember.t Loading test case finished
Using log file [/tmp/testplan.log]
Test plan [showcase.testplan] starts ... testcase [admin_principal_add_rpc.t]...success testcase [admin_principal_add_snmp.t]...success testcase [admin_policy_default_ui.t]...success testcase [admin_add_group.t]...success testcase [admin_edit_group_active-inactive.t]...success testcase [admin_edit_group_addgroupmember.t]...success testcase [admin_edit_group_cancle_editing.t]...success testcase [admin_edit_group_delete.t]...success testcase [admin_edit_group_descrīption.t]...success testcase [admin_edit_group_gid.t]...success testcase [admin_edit_group_name.t]...success testcase [admin_edit_group_removegroupmember.t]...success
================ summary report =================
total test 12, passed (12), failed (0), skipped (0) test case failed test case skipped test case success admin_principal_add_rpc.t admin_principal_add_snmp.t admin_policy_default_ui.t admin_add_group.t admin_edit_group_active-inactive.t admin_edit_group_addgroupmember.t admin_edit_group_cancle_editing.t admin_edit_group_delete.t admin_edit_group_descrīption.t admin_edit_group_gid.t admin_edit_group_name.t admin_edit_group_removegroupmember.t log file: [/tmp/testplan.log]
================ end of summary report =================
|
调用单个程序的主程序如下:
#!/usr/bin/perl
use strict; use warnings;
#******** Global variables ********# our $testplanfile; our @testcases; our $total=0; our $pass=0; our $fail=0; our $skip=0; our @case_passed; our @case_failed; our @case_skipped; our $log="/tmp/testplan.log";
#**************************# our $x=@ARGV; if ($x==1){ $testplanfile = $ARGV[0]; print "\nUsing test plan file [$testplanfile]"; print "\nUsing default log file [$log]"; loadtestcases(); } elsif ($x==2){ $testplanfile = $ARGV[0]; $log = $ARGV[1]; print "\nUsing test plan file [$testplanfile]"; loadtestcases();
if (!open (LOG , ">$log")){ print "\nopen to write [$log] ERROR"; exit (0); } print "\nUsing log file [$log]"; }else{ print "\nUsage: exetestplan.pl <testplan> <log file>\n"; exit (0); }
#**************************# print "\n\nTest plan [$testplanfile] starts ..."; foreach my $testcase (@testcases){ my $testresult = run_one_test($testcase); $total ++; if ($testresult == 0){ # if test failed $fail++; push @case_failed, $testcase; } if ($testresult == 1){ # if test success $pass++; push @case_passed, $testcase; } if ($testresult == 2){ # if test scrīpt file does not exist $skip++; push @case_skipped, $testcase; } } print "\n================ summary report =================\n"; print "\ntotal test $total, passed ($pass), failed ($fail), skipped ($skip)"; print "\ntest case failed"; foreach (@case_failed){ print "\n ".$_; } print "\ntest case skipped"; foreach (@case_skipped){ print "\n ".$_; } print "\ntest case success"; foreach (@case_passed){ print "\n ".$_; } close LOG; print "\nlog file: [$log]\n"; print "\n\n================ end of summary report =================\n";
#******** sub routines ********#
sub run_one_test{ my $testscrīpt = shift; my $cmd; my $return; my $result; my @ok; my @notok; my $subtotal=0; my $subpass=0; my $subfail=0;
print LOG "\n"; print LOG gettimestamp()."[$testscrīpt] starts ..."; print "\ntestcase [$testscrīpt]..."; if (-e $testscrīpt){ $cmd="perl $testscrīpt 2>&1"; }else{ print "skipped"; print LOG gettimestamp()."file [$testscrīpt] does not exist, skip this one"; return 2; } print LOG gettimestamp()."cmd is [$cmd]"; $result =`$cmd`; print LOG gettimestamp()."the testcase response is below"; my @lines = split(/\n/, $result ); foreach my $line (@lines){ print LOG "\n\t".$line; if ($line =~ /^ok/){ push @ok, $line; $subtotal++; $subpass++; } if ($line =~ /^not ok/){ push @notok, $line; $subtotal++; $subfail++; } } print LOG gettimestamp()."end of the testcase response"; print LOG gettimestamp()."total steps $subtotal, passed ($subpass), failed ($subfail)"; print LOG gettimestamp()."the following test steps success:"; foreach my $okline (@ok){ print LOG gettimestamp().$okline; } print LOG gettimestamp()."the following test steps failed"; foreach my $notokline (@notok){ print LOG gettimestamp().$notokline; } print LOG gettimestamp()."[$testscrīpt] ends"; if (($subtotal == $subpass) && ($subtotal > 0)){ print "success"; return 1; }else{ print "failed"; return 0; } }#run_one_test
sub gettimestamp { # return current string type timestamp my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time) ; my $timestamp = ($year+1900)."/".($mon+1)."/".$mday.":".$hour.":".$min.":".$sec; return "\n[".$timestamp."] "; }#gettimestamp
sub loadtestcases{ print "\n\tLoading test plan file..."; if (!open(TESTPLAN, $testplanfile)){ print "\nCan not read test plan file [$testplanfile]"; exit(0); } my $single_testcase; while ($single_testcase = <TESTPLAN>){ next if $single_testcase =~ m/^#/; # ignore commends line ==> starts with "#" char next if $single_testcase =~ m/^\s*$/; # ignore empty lines chop $single_testcase; $single_testcase =~ s/^\s*//g; $single_testcase =~ s/\s*$//g; print "\n\tLoad $single_testcase"; push @testcases , $single_testcase; } close TESTPLAN; print "\n\tLoading test case finished\n"; }
|
相关阅读:
- 写一个最最简单的perl module (yipoint, 2008-5-03)
- 网页自动测试 1. overview (yipoint, 2008-5-06)
- 网页自动测试 2. 理解selenium的perl 工具 (yipoint, 2008-5-06)
- 网页自动测试 3.一个独立的测试单元 (yipoint, 2008-5-06)
- 网页自动测试 4. 全盘设计 (yipoint, 2008-5-07)
- 网页自动测试 4. 全盘设计 (2) (yipoint, 2008-5-07)
- 网页自动测试 4. 全盘设计 (3) (yipoint, 2008-5-08)
- 网页自动测试 思考 :能否用被测试的软件去证明它自己 (yipoint, 2008-5-08)
- 网页自动测试 5. 细节的开始 (yipoint, 2008-5-10)
- 网页自动测试 6. 细节的继续和完成 (yipoint, 2008-6-03)
收藏
举报
TAG:
automation