Automating DB Unit Tests in Visual Studio 2012 using TFS Build Definitions

A few months ago we upgraded our Database solution for DB Pro in VS 2010 to SSDT 2012.  Just before that I set up some database unit tests but these got forgotten about after the upgrade.

I’ve just been working on getting these back up and running so we can add new tests for the new work we’re going to be doing.  All our DB unit tests are in their own solution rather than being a project within our database solution.  This is because we run our tests as part of a TFS build and the build always complained unless the project was in it’s own solution.  I simply opened this DB unit test solution and it was automatically upgraded.

In 2010 we had a Test List file that grouped the tests into different lists and we just had to tell the build definition which tests from which lists to run.

However, in 2012 the Test Lists are deprecated and we now have to use Test Categories (although they are still supported if you do still want to use them – see below).  There is no Test Category file to replace the Test List file and we need to specify the category or categories in the method declaration for the test.  In the example below I’m assigning the test Scribe_Log_ServiceBrokerETLQueueSend to the categories ETL and ETL_StoredProcedures.

DB Unit Test Categories

Now we just need to configure a new Build Definition in TFS.  In the Process tab choose the Default Template and in the Projects to Build select your DB Unit Test solution.

Now click the ellipses on the Automated Tests row and a new window should open.  Click on Add and the Add/Edit Test Run window will open.  I’m going to use the Visual Studio Test Runner but if you do still want to use your Test List file (.vsmdi) you can use the MSTest Test Metadata File Test Runner.  You can leave the General tab with the default values or updated as you require but on the Criteria tab simply enter TestCategory=ETL as the Test case filter, obviously replacing “ETL” with the name of your Test Category.

You can also use the Test Category if you choose the MSTest.exe Runner and in this case simply enter the name of the Test Category in the Test category criteria text box on the Criteria tab.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s