30.06.2013 Views

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5: Testing Databases<br />

A testing tool<br />

Having set up the test lab, source control, schema management, and auto deployment,<br />

it's time to think about how to actually write the tests. My tool of choice is NUnit (http://<br />

www.nunit.org) which, along with similar tools such as xUnit or MBUnit, requires<br />

the test code to be written in a .NET language such as C# or VB.NET. An alternative<br />

approach is a unit testing tool such as T<strong>SQL</strong>Unit (http://sourceforge.net/apps/trac/<br />

tsqlunit/), which allows tests to be written in T-<strong>SQL</strong>. When testing databases, this may<br />

feel like a good fit, but it's a tool I've tried and now avoid, mainly because it violates my<br />

"Don't store any unnecessary objects in <strong>SQL</strong> <strong>Server</strong>" principle.<br />

Every extra object means more space is taken up; not just space on disk, but memory<br />

space for associated execution plans and cached data pages. Sure, those can be flushed,<br />

but this just means extra work for the database engine.<br />

For these reasons, I think that tests have no place in a database and, in any event, I find<br />

that tests written in .NET are far easier to manage and run.<br />

A data generation tool<br />

Testing often requires a database to be populated with known test data. It is not always<br />

appropriate to use production data in a development environment, and manually creating<br />

test data can be a monotonous, time-consuming task.<br />

One solution to this problem is to use a tool such as <strong>SQL</strong> Data Generator (SDG) to help<br />

create realistic test data. It has a simple graphical user interface that allows you to choose<br />

the type of data you want to generate for each table and column, and it automatically<br />

assigns a generator to each column, <strong>based</strong> on its table name, column name, data type, and<br />

length. If the column has constraints, SDG uses these to set the generator parameters for<br />

the column (you can change the generator used by a particular column later, if required).<br />

140

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!