473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Testing and documentation tip

Over the last few days, I've come up with and played with what's turned out to
be a really useful technique that helps to test and document stored
procedures.

Pretty much any time you write a stored procedure, you run some tests to make
sure it's working as it should, but why discard these tests when you're done
with them, or store them somewhere that only you know how to find them, and
even you could forget? Instead, why not just put the entire test script in a
comment block in the procedure definition itself? This way, to run the tests
again later, just highlight the test block in Query Analyzer, and go.
Furthermore, the embedded test code is good documentation for how the
procedure is intended to be used, and indicates how well tested it is.

The example is kind of a simple case because it doesn't interact with data,
but if it did, the test could start a transaction, prepare some data, call the
procedure, check the result, then roll back the transaction to keep the
effects from messing up data or interfering with a subsequent test.

Example:

CREATE PROCEDURE dbo.procSJPreGetLine
@Text NVARCHAR(4000),
@StartAt INTEGER OUTPUT,
@LineText NVARCHAR(4000) OUTPUT
AS

DECLARE @NextLineStart INTEGER

SELECT @StartAt=COALESCE(@StartAt,1)

IF @Text IS NULL OR @StartAt>LEN(@Text) BEGIN
SELECT @LineText=NULL, @StartAt=0
RETURN
END

SELECT @NextLineStart = CHARINDEX(dbo.fnCrLf(), @Text, @StartAt)

IF @NextLineStart>0 BEGIN
SELECT @LineText = SUBSTRING(@Text, @StartAt, @NextLineStart-@StartAt)
SELECT @StartAt = @NextLineStart + LEN(dbo.fnCrLf())
END ELSE BEGIN
SELECT @LineText = SUBSTRING(@Text, @StartAt, LEN(@Text)-@StartAt+1)
SELECT @StartAt = LEN(@Text)+1
END

/*
-- Test script:
DECLARE
@Text NVARCHAR(4000),
@StartAt INTEGER,
@LineText NVARCHAR(4000)
SELECT @Text =
'abc
def'

EXEC dbo.procSJPreGetLine @Text, @StartAt OUTPUT, @LineText OUTPUT
PRINT CASE WHEN @LineText = 'abc' THEN 'Line 1 - OK' ELSE 'Line 1 bad - ' +
@LineText END
EXEC dbo.procSJPreGetLine @Text, @StartAt OUTPUT, @LineText OUTPUT
PRINT CASE WHEN @LineText = 'def' THEN 'Line 2 - OK' ELSE 'Line 2 bad - ' +
@LineText END
*/

Jul 20 '05 #1
0 1149

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jonathan Allen | last post by:
We have found that our method of testing does not match traditional text-book methodologies. I decided to write a short white paper on it so that I could get your opinions. Does anyone else use...
38
by: Christoph Zwerschke | last post by:
In August 2001, there was a thread about the "Art of Unit Testing": http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 Paul Moore asked the...
1
by: serge | last post by:
I've started researching on Unit Testing and I must admit I had never heard of Unit Testing until a couple of months ago. Obviously I am interested in Unit Testing Stored Procedures. I read the...
4
by: Pablo Cedeno | last post by:
Hi all, I'm looking for a testing tool to test my web application made in aspx I started working with JMeter but i'm lost in this. I made the simpliest test, get an aspx page, but now i need to...
44
by: John A. Bailo | last post by:
Dr. Dobbs has a /glowing/ article on Ruby on Rails this month. What do you guys think? Can it replace .net, php and java? And be the Open Source OOP web solution that is not bound to Sun or...
58
by: nw | last post by:
Hi, I have been asked to teach a short course on testing in C++. Until now I have used my own testing classes (which from what I've seen seem similar to the boost unit testing classes)....
1
by: Software Engineer | last post by:
Learn Software Testing http://trailfire.com/frank/marks/34684 If you are a software QA engineer or someone interested in software testing, this trail is for you. It covers software testing...
4
by: cmay | last post by:
I have been looking on and off for the past 6 months or so for some kind of guidance for creating asp.net unit tests with Visual Studio Team System, but I have yet to find anything significant. ...
4
by: David | last post by:
Hi list. Do test-driven development or behaviour-driven development advocate how to do higher-level testing than unit testing? types of testing: unit integration system
0
by: mo.sparrow | last post by:
The advantages of unit testing are well known, giving development teams a safety net to facilitate change, ease integration and supply live documentation.Unit testing of small logical code is quite...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.