Running SQL database unit tests

To run all tests against a database

1. In Object Explorer, right-click a connected database or a specific database object, click Unit Test, and then click Run All Tests.

2. After the tests are completed, the Test Results window appears. The window displays a grid containing details for each test. Specifically, it shows the status of a test (failed or succeeded), test name, class name, and error message (if any).

View test results in the Test Results window

There are several buttons on the Test Results toolbar for managing the results of tests, in particular:

Click Run Checked Tests to re-run all the checked tests Run Checked Tests (Ctrl+R) reruns all the checked tests.

Click Run All Tests to re-run all the tests Run All Tests reruns all the tests.

Click Stop to stop running the tests Stop Tests stops running the tests.

You can also right-click the test results grid to call a shortcut menu.

Manipulte unit tests from the shortcut menu of the Test Results window

The Run Selected Test(s) option allows rerunning the selected test(s).

The Open Test option allows opening the required test in a new SQL document.

The Run Checked Tests (Ctrl+R) option allows rerunning the checked test(s).


When you select the Run Checked Test(s) option, Unit Test runs all tests labeled with check marks. By default, all tests are labeled with check marks. In order not to clear the checkboxes if you need to run only one or a couple of tests, you can click to select the required test, then right-click it and click Run Selected Test(s). To select several tests, hold Ctrl. When you select Run Selected Test(s), Unit Test does not run the tests labeled with check marks, but only the tests that are selected. They are highlighted in yellow.

Running tests from the Test List Manager

You can also run tests from the Test List Manager. It allows running all tests, selected tests, and checked tests.

To run all tests

You can select the Run All Tests option in a shortcut menu that can be opened by right-clicking the sample database or the test class in the navigation tree as well as by right-clicking a test in the tests list.

To run checked tests

Right-click any test in the test list to open a shortcut menu with the Run Checked Test(s) option.

To run selected tests

Right-click any test in the test list to open a shortcut menu with the Run Selected Test(s) option.


To learn more about Test List Manager, see the Viewing test list topic.

The indicators of test status

In the Test Results list, the icon before the test name shows the status of the test:

Icon Name Description
Test Failed Status Failed Indicates that the test has failed
Test Succeeded Status Succeeded Indicates that the test has passed
Test Executing Status Executing Indicates that the test is being executed
Test Pending Status Pending Indicates that the test execution is paused