tSQLt.NewTestClass [@ClassName = ] 'class name'
[@ClassName = ] ‘class name’
The name of the test class to be created
Return Code Values
An error may be raised if the test class already exists and an object belonging to it cannot be dropped.
tSQLt.NewTestClass creates a new test class. A test class is simply a schema where the user can create test case procedure and any other related objects. If a schema with the same name as the test class already exists, the schema is dropped first.
Stored procedures in the test class schema are considered test cases if their name begins with ‘test’.
All test case stored procedures should be created in a schema which was created with tSQLt.NewTestClass.
Example: Creating a test class and test case
EXEC tSQLt.NewTestClass 'testFinancialApp'; GO CREATE PROCEDURE testFinancialApp.[test that SalesReport calls HistoricalReport when @showHistory = 1] AS BEGIN -------Assemble EXEC tSQLt.SpyProcedure 'FinancialApp.HistoricalReport'; EXEC tSQLt.SpyProcedure 'FinancialApp.CurrentReport'; -------Act EXEC FinancialApp.SalesReport 'USD', @showHistory = 1; SELECT currency INTO actual FROM FinancialApp.HistoricalReport_SpyProcedureLog; -------Assert HistoricalReport got called with right parameter SELECT currency INTO expected FROM (SELECT 'USD') AS ex(currency); EXEC tSQLt.assertEqualsTable 'actual', 'expected'; -------Assert CurrentReport did not get called IF EXISTS (SELECT 1 FROM FinancialApp.CurrentReport_SpyProcedureLog) EXEC tSQLt.Fail 'SalesReport should not have called CurrentReport when @showHistory = 1'; END; GO
In the following code example...
-------Assert HistoricalReport got called with right parameter
FROM (SELECT 'USD') ex(currency);
...what is the purpose of "ex(currency)"?
@ThatGuyDuncan When you specify a subquery as your row source for a SELECT...INTO, you need to alias it and all its columns. "ex(currency)" is a combination of table and column alias to fulfill that requirement.
I will add the "AS" keyword in the example to make that more obvious.