2014-09-28
待测程序
测试程序
创建测试用例以及测试结果存储
执行T-SQL脚本
使用BCP工具导入测试用例数据
创建T-SQL 测试套件
当待测存储过程返回行集的时候,如何判断测试结果是否通过
当待测存储过程返回out参数时,如何判断测试结果是否通过
当待测存储过程没有返回值时,如何判断测试结果是否通过
许多基于Windows的系统都使用了SQL Server作为后台组件。待测程序经常通过存储过程来访问数据库。对于这些应用场景,可以把SQL存储过程当成应用程序的辅助函数。有两种方法可以用来编写对SQL存储过程的自动化测试:
- 测试套件代码用T-SQL语言来编写,在类似于查询分析器(Query Analyzer)或者Management Studio这样的程序里执行
- 测试套件代码用.NET语言连编写
待测程序
下面代码创建数据库‘dbEmployees’;创建表‘talEmployee’,插入相应数据;创建存储过程‘usp_HireAfter’,创建登陆用户‘employeesLogin’并赋予访问数据库和存储过程的权限:
makeDbEmployees.sql:
1 -- Database setup: makeDbEmployees.sql 2 3 use master 4 go 5 6 if exists (select * from sysdatabases where name='dbEmployees') 7 drop database dbEmployees 8 go 9 10 if exists (select * from syslogins where name = 'employeesLogin') 11 exec sp_droplogin 'employeesLogin' 12 go 13 14 create database dbEmployees 15 go 16 17 use dbEmployees 18 go 19 20 create table tblEmployees 21 ( 22 empID char(3) primary key, 23 empLast varchar(35) not null, 24 empDOH datetime not null, 25 ) 26 go 27 28 -- this is dev data, not test case data 29 insert into tblEmployees values('e11','Adams', '06/15/1998') 30 insert into tblEmployees values('e22','Baker', '06/15/2001') 31 go 32 33 exec sp_addlogin 'employeesLogin', 'September,2014' 34 go 35 exec sp_grantdbaccess 'employeesLogin' 36 go 37 38 create procedure usp_HiredAfter 39 @dt datetime 40 as 41 select * from tblEmployees where empDOH > @dt 42 go 43 44 grant execute on usp_HiredAfter to employeesLogin 45 go 46 47 -- end script