Testing Stored Procedure

Hi All,

I am using sql server 2012. I have a stored procedure which i am refactoring. The functionality is same between old and new SPs but the new Sp is faster and adheres to best practices and coding standards more. This Sp take 15 parameters. So i have atleast 30 scenarios where i need to perform testing, compare the results with old SP to ensure that the results of old SP and new SP are same. I already performed two rounds of such testing and i have some more changes to be done and need to test all the scenarios again.

Is there any way i can automate this? like i run all the queries for testing once and if any query fails message will be written to log file.
So for given set of input values i need to run old SP, save results in a file, run new Sp save results in a file compare both files and if they are same then log that its passed. Is this correct? If yes how to go about this?

Thanks for your time.
JyozealAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TONY TAYLORCommented:
I think the biggest problem with this question is that a stored proc can do almost anything.  You have not stated what it actually does and what qualifies as a "good result" and what validates as a "bad result".

If it is a simple "does an error occur," I would say put all your "testing values" in a temp table, iterate through it with a cursor and hit the stored proc with those values.  If, at the end you have no errors, viola!
0
JyozealAuthor Commented:
Thanks for your reply. The SP returns results based on search criteria. For ex: one of the parameters is @filterexpression. If "james" is entered as filter expression then all records with ' james' in their first or last name is the result set.

For old version of Sp - Exec SearchResults_Old @filterexpression ='james'

For new version of Sp - Exec SearchResults_New @filterexpression ='james'

If both return same no of records with same no of columns and same values in each column then the test case is passed and the same should be logged.
0
TONY TAYLORCommented:
Your output may have different columns depending on the search?  This is not a standardized search results dataset?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JyozealAuthor Commented:
It will most probably not have different columns. But i still need to test for the same.
While trying to make the SP faster i used dynamic sql where as old one uses temp tables. So for each set of unique input values i need same results from both versions of SP so i need to test if same data is output by both versions.
0
TONY TAYLORCommented:
Why don't you try something like this?

-- IF TEMP TABLES EXIST, DROP THEM (MULTIPLE RUNS) 
IF OBJECT_ID('TEMPDB..#OLD_TABLE') IS NOT NULL
	DROP TABLE #OLD_TABLE
IF OBJECT_ID('TEMPDB..#NEW_TABLE') IS NOT NULL
	DROP TABLE #NEW_TABLE

-- CREATE TEMP TABLES
CREATE TABLE #OLD_TABLE ( Field1 varchar(100), Field2 varchar(100), Field3 varchar(100) )
CREATE TABLE #NEW_TABLE ( Field1 varchar(100), Field2 varchar(100), Field3 varchar(100) )

-- FILL RESULTS
INSERT INTO #OLD_TABLE 
EXEC SearchResults_Old @filterexpression ='james' 

INSERT INTO #NEW_TABLE 
EXEC SearchResults_New @filterexpression ='james' 

-- TEST DIFFERENCES
IF EXISTS(SELECT * FROM #OLD_TABLE EXCEPT SELECT * FROM #NEW_TABLE)
	PRINT '''james'' returned exception from old table to new table.'

-- TEST DIFFERENCES
IF EXISTS(SELECT * FROM #NEW_TABLE EXCEPT SELECT * FROM #OLD_TABLE) 
	PRINT '''james'' returned exception from new table to old table.'

-- TEST ROW COUNT
IF EXISTS(
	SELECT *
	FROM 
		(SELECT SUM(1) AS REC_CT FROM #OLD_TABLE) OT
		CROSS APPLY (SELECT SUM(1) AS REC_CT FROM #NEW_TABLE) NT 
	WHERE OT.REC_CT <> NT.REC_CT 
)
	PRINT '''james'' returned different row counts between new table and old table.'

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TONY TAYLORCommented:
Previous will not work with dynamic fields...
0
JyozealAuthor Commented:
will try this and get back to you.
0
JyozealAuthor Commented:
This helped.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.