Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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 in those tests 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 haven't 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 2010 Test 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.
Rerun 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).
Interpret test results
After you run your tests, the Test Results window shows which tests have passed or failed. For more information, see Interpret SQL Server unit test results. For more information about how to diagnose an unexpected failure, see How to: Debug Database Objects.
In this section
This section contains the following articles:
- How to: Debug Database Objects
- How to: Run SQL Server Unit Tests from Team Foundation Build
- How to: Run SQL Server unit tests
- Interpret SQL Server unit test results
Related scenarios
Create and define 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 can't verify by using the default test conditions.