<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Roland &#187; TSQL</title>
	<atom:link href="http://www.chrisroland.info/category/tsql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisroland.info</link>
	<description>Software, Web and Database Developer</description>
	<lastBuildDate>Sun, 26 Dec 2010 00:44:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Performance unit testing with TSQLUnit</title>
		<link>http://www.chrisroland.info/performance-unit-testing-with-tsqlunit/</link>
		<comments>http://www.chrisroland.info/performance-unit-testing-with-tsqlunit/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 14:32:25 +0000</pubDate>
		<dc:creator>Chris Roland</dc:creator>
				<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://www.chrisroland.info/?p=28</guid>
		<description><![CDATA[I&#8217;m working on a project to migrate several databases from SQL Server 2000 to SQL Server 2008 and I wanted a way to validate performance through unit testing. TSQL unit testing is extremely easy with TSQLUnit.  I was able to get up and running within minutes and it doesn&#8217;t require a ton of bloated software [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project to migrate several databases from SQL Server 2000 to SQL Server 2008 and I wanted a way to validate performance through unit testing.</p>
<p>TSQL unit testing is extremely easy with TSQLUnit.  I was able to get up and running within minutes and it doesn&#8217;t require a ton of bloated software to use.  All you need to do is run a single SQL script and voila you&#8217;re done.</p>
<p>You can read more about TSQLUnit at: <a href="http://sourceforge.net/projects/tsqlunit/">http://sourceforge.net/projects/tsqlunit/</a></p>
<p>I setup a simple test using TSQLUnit to test the execution time of a very simple stored procedure which returns the average reads from a performance counter table.  </p>
<p>The stored procedure I was testing was:<br />
<code><br />
CREATE PROCEDURE [dbo].[GetAverageReads]<br />
	@AVGReads INT OUT<br />
AS<br />
	SET NOCOUNT ON<br />
	SELECT @AVGReads = AVG(Reads)<br />
	FROM dbo.TRACE_20090325<br />
</code></p>
<p>The TSQLUnit test I used was:<br />
<code><br />
CREATE PROCEDURE [dbo].[ut_TestGetAverageReads]<br />
AS<br />
	SET NOCOUNT ON</p>
<p>	DECLARE @startTime DATETIME<br />
	DECLARE @endTime DATETIME<br />
	SET @startTime = GETDATE()</p>
<p>	DECLARE @AVGReads INT<br />
	EXEC dbo.GetAverageReads @AVGReads OUT		</p>
<p>	SET @endTime = GETDATE()<br />
	DECLARE @elapsedTime INT<br />
	SET @elapsedTime = DATEDIFF(ms, @startTime, @endTime)</p>
<p>	IF (@elapsedTime > 1000)<br />
		EXEC dbo.tsu_Failure 'GetAverageReads exceeded time.'<br />
</code></p>
<p>The test checks to see if the stored procedure exceeded 1 second (1000 ms) and if so, the test will fail.  Because the row count is low and the stored procedure is simple, the test passes.  To see what the test results would look like if the test failed I changed the comparison to use 1 ms instead of 1000 ms.  </p>
<p>Here is the test failure result when running the tsu_runTests stored procedure:<br />
<code><br />
=======================================================<br />
Run tests starts:Jul  9 2009 10:26AM<br />
Warning: Null value is eliminated by an aggregate or other SET operation.<br />
=======================================================<br />
Testsuite:  (1 tests ) execution time: 143 ms.<br />
>>> Test: ut_TestGetAverageReads     GetAverageReads exceeded time.<br />
-----------------------------------------------------------------------<br />
 Run tests ends:Jul  9 2009 10:26AM<br />
 Summary:<br />
     1 tests, of which 1 failed and 0 had an error.</p>
<p>     FAILURE!<br />
-----------------------------------------------------------------------<br />
=======================================================<br />
</code></p>
<p>This provides a base to start from as I work on the performance unit tests.  You will want to do profiling and other performance tests.  The performance unit tests provide a quick way to identify areas that exceed your performance requirements. </p>
<p>The tests can then be used within the build/CI environment, as a way to quickly identify any performance issues with a new build.</p>
<p>If you have any questions or feedback on this post, I would greatly appreciate it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisroland.info/performance-unit-testing-with-tsqlunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

