NewTestClass

 

Syntax

tSQLt.NewTestClass [@ClassName = ] 'class name'

Arguments

[@ClassName = ] ‘class name’
The name of the test class to be created

Return Code Values

Returns 0

Error Raised

An error may be raised if the test class already exists and an object belonging to it cannot be dropped.

Result Sets

None

Overview

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’.

Limitations

N/A

Warnings

All test case stored procedures should be created in a schema which was created with tSQLt.NewTestClass.

Examples

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') 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

NewTestClass

tSQLt.NewTestClass [@ClassName = ] 'class name'

Arguments

[@ClassName = ] ‘class name’
The name of the test class to be created

Return Code Values

Returns 0

Error Raised

An error may be raised if the test class already exists and an object belonging to it cannot be dropped.

Result Sets

None

Overview

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’.

Limitations

N/A

Warnings

All test case stored procedures should be created in a schema which was created with tSQLt.NewTestClass.

Examples

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') 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
 Posted by at 5:09 pm
0 comments