Create new SQL unit tests using tSQLt

The guide explains how to create a new SQL unit test for a specific database using the tSQLt framework.

Prerequisite

Install a tSQLt framework.

Add a test

1. Open the Add New Test dialog by doing one of the following:

  • On the top menu, select Database > Unit Test > Add New Test.
  • In Database Explorer, right-click the required database and select Unit Test > Add New Test.

2. Under Test Location, choose the required connection and database.

3. Under Test Information, specify a test name and enter or choose a test class name to which the new test will be added.

Note

A test class is a special schema that contains one or more related tests.

Add a new test

Warning

If a test with the same name already exists, dbForge Studio displays a Test creation failed message indicating that an object with that name already exists in the database.

4. Click Add Test.

The dialog shows the progress. After the operation is complete, the following message appears:
The test has been successfully created.

5. Click Finish to close the dialog.

The unit test template opens in SQL Editor, where you can edit and execute it.

Unit test template

Add a test from Test List Manager

1. Open Test List Manager by doing one of the following:

  • In the top menu, select Database > Unit Test > View Test List.
  • In Database Explorer, right-click the required database or test class and select Unit Test > View Test List.

2. In the Test Projects tree, right-click the required database or test and select Add New Test.

Add a test from Test List Manager

Alternatively, right-click the grid and select Add New Test.

3. Follow the steps from the Add a test section to complete the process.