Run tSQLt tests
tSQLt: the Quick Start guide at tsqlt.org.
Code examples: a ZIP archive (3.3 KB) from the tSQLt tutorial at tsqlt.org.
tSQLt is a framework for unit testing on Microsoft SQL Server. You can use it to test stored procedures, functions, views, and triggers of a database.
After the installation, the tSQLt script creates the tSQLt
schema that stores framework functions and procedures. Some procedures have the Private_
prefix and can be used only by the framework.
For illustration purposes, you can create the FinancialApp
schema from the tSQLt tutorial at tsqlt.org.
Uncompress tSQLt_demo.zip. A link to the archive is at the beginning of this topic.
In DataGrip, navigate to File | Open.
Right-click the Microsoft SQL Server data source and select Run SQL Script.
In the file browser, navigate to the demoApp.sql from the tSQLt_demo.zip archive.
In tSQLt, all tests are collected under a single class. A class is a schema.
To create a new class, use the
NewTestClass
procedure. For example,EXEC tSQLt.NewTestClass 'testFinancialApp'
.
In the Database Explorer (View | Tool Windows | Database Explorer) , right-click the Microsoft SQL Server data source and select Open Query Console.
Type the code of a test. You can take examples from the tSQLt tutorial.
Click the Execute button (
) or press CtrlEnter.
Click the N of N link near the data source name. In the schema selection window, select schemas that you created (for example,
tSQLt
,testFinancialApp
, andFinancialApp
).Press Enter.
Open the Run/Debug Configuration dialog in one of the following ways:
Select Run | Edit Configurations from the main menu.
With the Navigation bar visible (View | Appearance | Navigation Bar), choose Edit Configurations from the run/debug configuration selector.
Press AltShiftF10 and then press 00.
In the Run/Debug Configurations dialog, click the Add New Configuration icon (
) and select tSQLt Test.
Data source: the name of a data source. tSQLt supports Microsoft SQL Server.
Database: the name of a database (for example,
testFinancialApp
).Paths: a qualified path to the testing package (for example,
testFinancialApp.test that ConvertCurrency converts using given conversion rate
).
For more information about settings of the tSQLt Test configuration type, refer to tSQLt Test.
You can either run the configuration right away or save the configuration to run it later.
To save the run configuration for later, click OK.
To run the configuration right away, click Run.
![https://resources.jetbrains.com/help/img/idea/2024.3/db_run_tsqlt_tests.png](https://resources.jetbrains.com/help/img/idea/2024.3/db_run_tsqlt_tests.png)
In the Database Explorer (View | Tool Windows | Database Explorer) , double-click the test.
In the editor, click the Run icon
in the gutter and select Run <procedure_name>.
In the Run tool window, click the Rerun failed tests button
Thanks for your feedback!