标签:数据迁移 数据测试
很久没有写自己的blog了。自动化测试项目结束后,又参加了一些新项目,有些和测试自动化无关。目前做的是数据迁移测试,即把一个老系统的业务数据,迁移到新系统中。大部分测试都集中在数据的测试,主要根据BMD测试数据字段的对应关系。测试用例都是用SQL脚本写的。为了调用这些测试用例,也写了一个简单的测试框架,思路如下:
Main.sql
这个文件有两部分,
1) 生成一个TestResult表,记录每一个测试用例的结果,如:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N‘[dbo].[TestResult]‘) AND type in (N‘U‘)) DROP TABLE [dbo].[TestResult] BEGIN CREATE TABLE [dbo].[TestResult]( [ResultId] int identity(1,1) NOT NULL, [TestCaseId] nvarchar(255) NOT NULL, [ProcedureName] nvarchar(255) NOT NULL, [TestCaseResult] nvarchar(255) NOT NULL, [TestLog] nvarchar(max) NULL, [ExecutionTimeStamp] datetime NULL ) INSERT INTO [dbo].[TestResult] VALUES (‘C-301‘,‘AccountID‘,‘NOT RUN‘,‘‘,CURRENT_TIMESTAMP), ...... END
2) 调用每一个测试用例对应的存储过程。
EXECUTE C_AccountID
2. 每一部分数据都有自己的文件,如Account.sql. 在这个文件里,包括了将测试用例自动化的存储过程。Example:
--C-301--------------Start of AccountID Procedure------------------- USE TestDatabase GO IF OBJECT_ID (‘dbo.AccountID‘, ‘P‘) IS NOT NULL DROP PROCEDURE dbo.AccountID GO CREATE PROCEDURE dbo.AccountID AS BEGIN DECLARE @AccountIDCount int DECLARE @DupCount int DECLARE @LegalCount int DECLARE @Result nvarchar(10) DECLARE @Comments nvarchar(255) /* Test the account id‘s mapping */ SET @AccountIDCount = 0 SET @AccountIDCount = (SELECT COUNT(*) FROM [MasterData] T LEFT JOIN [TargetList] S ON CAST( T.[iAccountID] as nvarchar) = CAST( S.[PARTYID] as nvarchar) collate Latin1_General_CI_AS WHERE T.[iAccountID] IS NULL ) /* Check there is no duplicate account id */ SET @DupCount = 0 SET @DupCount = (SELECT COUNT(*) FROM [MasterData] WHERE (iAccountID in (select iAccountID from [MasterData] group by iAccountID having count(*)>1) )) /* check the account id is 10 digits */ SET @LegalCount = (SELECT * FROM [Rex_DCL5_LDS_Customer_STG_MasterData] WHERE iAccountID not like ‘%0000000000%‘) IF @AccountIDCount + @DupCount + @LegalCount= 0 BEGIN SET @Result = ‘PASS‘ SET @Comments = ‘[iAccountID] are correct.‘ END ELSE BEGIN SET @Result = ‘FAIL‘ SET @Comments = ‘There are: ‘ + CAST(@AccountIDCount as nvarchar) + ‘records of T data are not contained in S data.‘+ CAST(@DupCount as nvarchar) + ‘ records are duplicated‘ + CAST(@LegalCount as nvarchar) + ‘ records are illegal‘ END IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N‘[dbo].[TestResult]‘) AND type in (N‘U‘)) BEGIN UPDATE [dbo].[TestResult] SET TestCaseResult = @Result, TestLog = @Comments, ExecutionTimeStamp = CURRENT_TIMESTAMP WHERE ProcedureName = ‘AccountID‘ END END GO --C-301------------End of dbo.AccountID Procedure-------------------
执行测试是,先Acount.sql,生产每一个测试用例的存储过程,然后在打开Main.sql去调用这些存储过程。
这个框架本身非常简单,很容易扩展和维护,为进行数据迁移测试的童鞋们,抛砖引玉。
本文出自 “软件测试 自动化测试之路” 博客,转载请与作者联系!
标签:数据迁移 数据测试
原文地址:http://yazi0127.blog.51cto.com/1212316/1543487