Run Database Unit Tests
To improve and maintain the quality of your code, you can create and run database 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 database 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.
Ways to Run Database Unit Tests
You can run database unit tests in several ways that vary based on the software that you have installed, as the following table shows:
Action |
Database Edition |
Database Edition and Test Edition |
Database Edition and Team Foundation Server |
Database Edition and Visual Studio Team System |
---|---|---|---|---|
Run tests by using the Test View window. For more information, see How to: Run Database Unit Tests and How to: Run Selected Tests. |
Yes |
Yes |
Yes |
Yes |
Run tests by using the MSTest.exe command at a command prompt. For more information, see How to: Run Tests from the Command Line. |
Yes |
Yes |
Yes |
Yes |
Run tests from Solution Explorer by running a test project. For more information, see How to: Run Selected Tests. |
Yes |
Yes |
Yes |
Yes |
Re-run tests from the Tests Results window. For more information, see How to: Rerun a Test. |
Yes |
Yes |
Yes |
Yes |
Run individual tests or test lists from the Test List Editor window. For more information, see How to: Run Selected Tests. |
No |
Yes |
Requires Test Edition or Visual Studio Team System |
Yes |
Run tests as you build a project in Team Foundation Build. For more information, see How to: Configure and Run Build Verification Tests (BVTs). |
No |
Requires Team Foundation Server |
Yes |
Yes |
You can run your database unit tests in a particular order by using an ordered test. For more information, see How to: Create an Ordered Test.
Interpreting Tests Results
After you run your tests, the Test Results window shows which tests have passed or failed. For more information, see Interpreting Database Unit Test Results. For more information about how to diagnose an unexpected failure, see How to: Debug Database Objects.
Related Scenarios
Generate Test Data for Databases by Using Data Generators
Before you run a database unit test, you might want to insert representative data into your database. You can use a custom or built-in data generator to create realistic test data without exposing production data to your developers.Create and Define Database 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.Define Custom Conditions for Database Unit Tests
You can create a custom test condition to test for any condition that you cannot verify by using the default test conditions.