此部分内容创建一个轻量级T-SQL测试套件,总共有3个脚本。
用于创建测试平台数据和待测存储过程的脚本:
--======================
--makeDbTestAndResults.sql
use master
go
if exists (select * from sysdatabases where name = 'DbTestAndResults')
drop database makeDbTestAndResults
go
if exists (select * from sysxlogins where name = 'testLogin')
exec sp_droplogin 'testLogin'
go
create database makeDbTestAndResults
go
use makeDbTestAndResults
go
create table tb1TestCases
(
caseID char(4) primary key,
input datetime not null,
expectedChecksum int not null
)
go
--下面插入的是用于usp_HiredAfter的测试数据,采用了对期望值求校验和的方法
--也可以通过BCP,BTS或者C#程序从文本文件读入这些数据
insert into tb1TestCases values('0001','10/25/2009',1042032)
insert into tb1TestCases values('0002','10/25/2009',9999999)--deliberate error
insert into tb1TestCases values('0003','10/25/2008',25527856)
insert into tb1TestCases values('0004','10/10/2006',1042032)
go
create table tb1Results
(
caseID char(4) not null,
result char(4) not null,
whenRun datetime not null
)
go
exec sp_addlogin 'testLogin','secret'
go
exec sp_grantdbaccess 'testLogin'
go
grant select,insert,delete,update on tb1TestCases to testLogin
go
grant select,insert,delete,update on tb1Results to testLogin
go
--结束脚本
--makeDbTestAndResults.sql
use master
go
if exists (select * from sysdatabases where name = 'DbTestAndResults')
drop database makeDbTestAndResults
go
if exists (select * from sysxlogins where name = 'testLogin')
exec sp_droplogin 'testLogin'
go
create database makeDbTestAndResults
go
use makeDbTestAndResults
go
create table tb1TestCases
(
caseID char(4) primary key,
input datetime not null,
expectedChecksum int not null
)
go
--下面插入的是用于usp_HiredAfter的测试数据,采用了对期望值求校验和的方法
--也可以通过BCP,BTS或者C#程序从文本文件读入这些数据
insert into tb1TestCases values('0001','10/25/2009',1042032)
insert into tb1TestCases values('0002','10/25/2009',9999999)--deliberate error
insert into tb1TestCases values('0003','10/25/2008',25527856)
insert into tb1TestCases values('0004','10/10/2006',1042032)
go
create table tb1Results
(
caseID char(4) not null,
result char(4) not null,
whenRun datetime not null
)
go
exec sp_addlogin 'testLogin','secret'
go
exec sp_grantdbaccess 'testLogin'
go
grant select,insert,delete,update on tb1TestCases to testLogin
go
grant select,insert,delete,update on tb1Results to testLogin
go
--结束脚本