I've been working on migrating existing SQL Server database projects into
Visual Studio for Database Professional projects. Most of the existing databases
have imported without major problems, but there are a few that have warnings
about cross-database joins in old unit tests.
TSD3025: The following cross-database dependencies could
not be verified: ... Your database application might fail at runtime when
... is executed.
If you are tired of being warned about a known issue, Data Dude allows you to
suppress warnings, in the database project's build properties (Project ->
Properties -> Build tab -> Suppress Warnings).
Simply put the warning numbers you want to ignore in there (without "TSD" at
the front) and save. Separate numbers with a semi colon (" ; ").
For a complete list of the errors in Data Dude, see
Gert's page.
I just handed a work mate an output script from DataDude, which he ran in
Management Studio. Instead of producing the expected database he ended up with
one called $(DatabaseName)
Remember database pro uses SQLCMD to deploy databases
If you use Management Studio to run an output script, you'll need to swap
into SQLCMD mode through the Query -> SQLCMD Mode menu. Or click the red
exclaimation icon in your toolbar
I've been migrating unit tests to a new Visual Studio Database Professionals
project. So far there's been no problems (other than trying to find a naming
standard). This problem had me scratching my head for a few minutes today.
SELECT TOP 1
@ItemCode = ItemCode,
@PriceLevel = PriceLevel
FROM dbo.Price
EXEC dbo.GetItemPrice @ItemCode, @PriceLevel
Running the unit test was resulting in the error:
Error Message Test method PricingTests.StoredProcedures.dbo_GetItemPrice threw
exception: System.Data.SqlClient.SqlException: Procedure or Function 'GetItemPrice'
expects parameter '@PriceLevel', which was not supplied..
Debug Trace Execution test script...
Sql Error: 'Procedure or Function 'GetItemPrice' expects parameter '@PriceLevel',
which was not supplied.' (Severity 16, State 4).
Huh? I checked the SQL code twice. Yup, @PriceLevel is passed in as the
second parameter. What's up?
Ahhhh.... The parameters are defined in a different order. Time to swap from
positional parameters to named parameters to ensure values are passed into the
correct parameter
The correct way to call a stored procedure is using named parameters:
Remember to test the things that matter to customers/consumers of the app,
and things that other apps are dependant on. Make sure you react to test results
"otherwise it is entertainment"
James Bullock says.
Now that Microsoft have released Visual Studio Team Suite for Database
Professionals (aka Data Dude) its time for SQL Server developers and dbas
to learn more about Unit Testing.
There is many different methods to test a database within the framework set
by Visual Studio. So how do you know which way is best?
Well one of the best books of unit testing I've read would be the
Big Book of Testing by James Bullock which should take you all of ten
minutes to read.
Before you get to stuck on how to test your database, read his book and learn
what is worthwhile testing.
Sachin has just
published a draft whitepaper on database unit testing using Team Edition for
Database Professionals.
The whitepaper includes details steps on creating your first unit test;
automatic test generation; the standard test conditions available; and even
delves briefly into the C#/VB.Net code used by the testing framework.
I highly recommend users of Database Professionals (Data Dude) read
this whitepaper.
There has been a lot of discussion in the
forums about which track of Visual Studio is required for the new Database
Professionals (Data Dude) Trial to install.
Database Professionals TRIAL requires Visual Studio 2005 Team Suite to be
installed.
The full product download on MSDN is a full image only, so 2.9 GB or so, if
you already own Visual Studio Team Suite, you can simply download the trial SKU
(which is only 20MB) and install this on top of your Team Suite instance. The
installer will detect that you have a full license instead of a trial license
and do the right thing.