您好,登錄后才能下訂單哦!
很久沒有寫自己的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去調用這些存儲過程。
這個框架本身非常簡單,很容易擴展和維護,為進行數據遷移測試的童鞋們,拋磚引玉。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。