数据迁移中的数据测试
很久没有写自己的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去调用这些存储过程。
这个框架本身非常简单,很容易扩展和维护,为进行数据迁移测试的童鞋们,抛砖引玉。
文章题目:数据迁移中的数据测试
URL分享:http://scjbc.cn/article/igogcd.html