tSQLt is the open source framework for unit testing on SQL Server
This project is maintained by tSQLt-org
tSQLt.Run [ [@testName = ] 'test name', [@TestResultFormatter =] 'test result formatter']
[@testName = ] ‘test name’
Optional. The name of a test case, including the schema name to which the test case belongs. For example ‘MyTestClass.[test employee has manager]’. If not provided, the test name provided on the previous call to tSQLt.Run within the current session is used. If no test cases have been run previously in the current session, then no test cases are executed. Optionally, ‘test name’ may be the name of a test class. In which case all tests on that class are executed.
[@TestResultFormatter = ] ‘test result formatter’
Optional. The name of the stored procedure(accessible to tSQLt) to format the test results. DefaultTestFormatter will be used if this value is not provided.
Returns 0
Raises an error containing the test case statistics if any test fails or errors. For example, if a test case fails, the following error is raised:
Msg 50000, Level 16, State 10, Line 1
Test Case Summary: 117 test case(s) executed, 116 succeeded, 1 failed, 0 errored.
None
(Note that tSQLt requires test procedure names to start with the four letters test.) tSQLt.Run is a flexible procedure allowing three different ways of executing test cases:
tSQLt.Run displays a test case summary. By default, the test case summary is a text based table. However, the result format can be changed using the stored procedure, SetTestResultFormatter.
N/A
N/A
-- Runs all the tests on MyTestClass
EXEC tSQLt.Run 'MyTestClass';
-- Runs [MyTestClass].[test addNumbers computes 2 plus 2 equals 4] and executes the SetUp procedure
EXEC tSQLt.Run 'MyTestClass.[test addNumbers computes 2 plus 2 equals 4]';
-- Runs using the parameter provided last time tSQLt.Run was executed
EXEC tSQLt.Run;