Running SQL Server Unit Tests
To improve and maintain the quality of your code, you can create and run SQL Server unit tests that verify the behavior of any database object and then check those tests in to version control. As you or any member of your team changes the database schema, you run both SQL Server unit tests and software unit tests to verify that the changes have not broken existing functionality. You can run individual tests, or you can run groups of tests, which are known as test lists. For more information, see Using Test Lists (Visual Studio 2010).
Ways to Run SQL Server Unit Tests
You can run SQL Server unit tests in several ways that vary based on the software that you have installed, as the following shows:
Run tests by using the Visual Studio 2010Test View window. For more information, see How to: Run SQL Server Unit Tests and How to: Run Automated Tests from Microsoft Visual Studio 2010. For Visual Studio 2012, see How to: Run Automated Tests from Microsoft Visual Studio 2012.
Run tests by using the MSTest.exe command at a command prompt. For more information, see How to: Run Automated Tests from the Command Line Using MSTest (Visual Studio 2010) or How to: Run Automated Tests from the Command Line Using MSTest (Visual Studio 2012).
Run tests from Solution Explorer by running a test project. For more information, see How to: Run Automated Tests from Microsoft Visual Studio 2010 or How to: Run Automated Tests from Microsoft Visual Studio 2012.
Re-run tests from the Tests Results window. For more information, see How to: Rerun a Test (Visual Studio 2010).
Run individual tests or test lists (Visual Studio 2010) from the Test List Editor window. For more information, see How to: Run Automated Tests from Microsoft Visual Studio 2010 or How to: Run Automated Tests from Microsoft Visual Studio 2012.
Run tests as you build a project in Team Foundation Build. For more information, see How to: Configure and Run Scheduled Tests After Building Your Application (Visual Studio 2010) or How to: Configure and Run Scheduled Tests After Building Your Application (Visual Studio 2012).
You can run your SQL Server unit tests in a particular order by using an ordered test. For more information, see How to: Create an Ordered Test (Visual Studio 2010) or How to: Create an Ordered Test (Visual Studio 2012).
Interpreting Tests Results
After you run your tests, the Test Results window shows which tests have passed or failed. For more information, see Interpreting SQL Server Unit Test Results. For more information about how to diagnose an unexpected failure, see How to: Debug Database Objects.
Topics in this Section
This section contains the following topics:
Related Scenarios
Creating and Defining SQL Server Unit Tests
You can define unit tests to verify the behavior of your database objects and associate each test project with a different data generation plan, deployment configuration, and connection string.
Custom Test Conditions for SQL Server Unit Tests
You can create a custom test condition to test for any condition that you cannot verify by using the default test conditions.