好久沒有寫本身的blog了。自動化測試項目結束後,又參加了一些新項目,有些和測試自動化無關。目前作的是數據遷移測試,即把一個老系統的業務數據,遷移到新系統中。大部分測試都集中在數據的測試,主要根據BMD測試數據字段的對應關係。測試用例都是用SQL腳本寫的。爲了調用這些測試用例,也寫了一個簡單的測試框架,思路以下:git
Main.sqlsql
這個文件有兩部分,app
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) 調用每個測試用例對應的存儲過程。ide
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去調用這些存儲過程。blog
這個框架自己很是簡單,很容易擴展和維護,爲進行數據遷移測試的童鞋們,拋磚引玉。ci