您好,登錄后才能下訂單哦!
很久沒有寫自己的blog了。自動化測試項(xiàng)目結(jié)束后,又參加了一些新項(xiàng)目,有些和測試自動化無關(guān)。目前做的是數(shù)據(jù)遷移測試,即把一個老系統(tǒng)的業(yè)務(wù)數(shù)據(jù),遷移到新系統(tǒng)中。大部分測試都集中在數(shù)據(jù)的測試,主要根據(jù)BMD測試數(shù)據(jù)字段的對應(yīng)關(guān)系。測試用例都是用SQL腳本寫的。為了調(diào)用這些測試用例,也寫了一個簡單的測試框架,思路如下:
Main.sql
這個文件有兩部分,
1) 生成一個TestResult表,記錄每一個測試用例的結(jié)果,如:
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) 調(diào)用每一個測試用例對應(yīng)的存儲過程。
EXECUTE C_AccountID
2. 每一部分?jǐn)?shù)據(jù)都有自己的文件,如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-------------------
執(zhí)行測試是,先Acount.sql,生產(chǎn)每一個測試用例的存儲過程,然后在打開Main.sql去調(diào)用這些存儲過程。
這個框架本身非常簡單,很容易擴(kuò)展和維護(hù),為進(jìn)行數(shù)據(jù)遷移測試的童鞋們,拋磚引玉。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。