SQL存储过程测试(8)——示例程序

发表于:2009-11-18 15:24

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:igoone    来源:51Testing软件测试博客

  自动化测试套件脚本:

--=================================
--SQLspTest.sql
--测试dbEmployees..usp_HiredAfter
--读入测试用例数据并把测试结果写回

set nocount on
if not exists(select * from master.dbo.sysdatabases where name='DbTestCasesAndResults')
 raiserror('Fatal error:dbTestCasesAndResults not found',16,1)
go

if exists(select * from sysobjects where name='tap_Reset')
 drop procedure tap_Reset
go

create procedure tap_Reset
as
 truncate table dbEmployees.dbo.tb1Employees

insert into dbEmployees.dbo.tb1Employees values('e11','Adams','10/25/2009')
insert into dbEmployees.dbo.tb1Employees values('e22','Baker','10/12/2009')
insert into dbEmployees.dbo.tb1Employees values('e33','Young','06/15/2001')
insert into dbEmployees.dbo.tb1Employees values('e44','Zetta','08/15/2003')

--其他数据在此处插入
exec tap_Reset
go

declare tCursor cursor fast_forward
 for select caseID,input,expectedChecksum
  from DbTestCasesAndResults.dbo.tb1Testcases
  order by caseID

declare @caseID char(4),@input datetime,@expectedChecksum int
declare @whenRun datetime
declare @resultMsg varchar(80)
declare @actualChecksum int

create table #resultRowset --for checksum technique
(
 empID char(3) primary key,
 empLast varchar(35) not null,
 empDOH datetime not null
)

set @whenRun = getdate()

print 'stored procedure under test = usp_HiredAfter'
print ' '
print 'CaseID Input Expected Actual Result'
print '==========================================='

open tCursor
fetch next
 from tCursor
 into @caseID,@input,@expectedChecksum

while @@fetch_status=0
begin
 exec tap_Reset --reset test bed data
 truncate table #resultRowset --empty out the result rowset
 insert #resultRowset(empID,empLast,empDOH) --call sp under test
 exec dbEmployees.dbo.usp_HiredAfter @input
 
 if(@@rowcount=0)
  set @actualChecksum=0
 else
  select @actualChecksum=checksum_agg(binary_checksum(*)) from #resultRowset
 
 if (@actualChecksum=@expectedChecksum)
  begin
   set @resultMsg=@caseID + ' ' + cast(@input as varchar(11)) +
   ' ' + cast(@expectedChecksum as varchar(20)) + ' ' +
      cast(@actualChecksum as varchar(20)) + 'Pass'
   print @resultMsg
   insert into dbTestCasesAndResults.dbo.tb1Results values(@caseID,'Pass',@whenRun)
  end
 else
  begin
   set @resultMsg=@caseID + ' ' + cast(@input as varchar(11)) +
   ' ' + cast(@expectedChecksum as varchar(20)) + ' ' +
      cast(@actualChecksum as varchar(20)) + 'FAIL'
   print @resultMsg
   insert into dbTestCasesAndResults.dbo.tb1Results values(@caseID,'FAIL',@whenRun)
  end
 fetch next
  from tCursor
  into @caseID,@input,@expectedChecksum

end

close tCursor
deallocate tCursor

drop table #resultRowset

相关阅读:

SQL存储过程测试(7)——当待测存储过程没有返回值时 如何判断测试结果是否通过

SQL存储过程测试(6)——当待测存储过程返回out参数时 如何判断测试结果是否通过

SQL存储过程测试(5)——当待测存储过程返回行集的时候 如何判断测试结果是否通过

SQL存储过程测试(4)——从T-SQL测试套件里把测试结果直接写入文本文件

SQL存储过程测试(3)——创建T-SQL测试套件

SQL存储过程测试(2)——使用BCP工具导入测试用例数据

SQL存储过程测试(1)——创建测试用例以及测试结果存储

33/3<123
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号