Asserts that stub object was called within current unit test execution with specified parameter value. Fails when pretend object were not called during current unit test execution, or when it was not called with the specified value.

Arguments

  • v_PretendObjectName – Name of the pretend object. Supports four part object name. SYSNAME data type.
  • v_ParameterName - Name of the parameter. SYSNAME
  • v_ParameterValue - Parameter value. NVARCHAR(MAX) 
  • v_NumberOfCalls - Expected number of calls, INT. If NULL value provided then this assert will check that pretend object called any number of times.
  • v_UserMessage – Message to report when assertion fails, NVARCHAR(MAX)

 

Note: If you are planning to run unit test manually, you must use DBTD_UNIT_TEST hint procedure to explicitly define a unit test procedure as the unit test.

Examples

SQL Server

/*Create inner procedure that will be called within outer scope*/

CREATE PROC AddNewUser

       @UserName     VARCHAR(50),

       @UserRole     VARCHAR(50)

AS

BEGIN

       --Do something

       PRINT @UserName

       PRINT @UserRole

END

GO

 

/*create unit test procedure*/

CREATE PROCEDURE UT_USERTESTS_AddNewUserK

AS

BEGIN

       --make sure that this test is the part of the USERTESTS suite

       EXEC DBTD_UNIT_TEST 'USERTESTS'

       --create mock for inner procedure

       EXEC DBTD_CREATE_STUB_PROCEDURE 'AddNewUse','STUB_AddNewUser', NULL

       

       --here we specifically do not call any business logic

       

       --assert that stub were called

       --and that it were called with expected parameter @UserName

       EXEC DBTD_ASSERT_STUB_CALLED_WITH_PARAM

              @v_PrependObjectName  = 'AddNewUser',

              @v_ParameterName      = '@UserName',  

              @v_ParameterValue     = 'Kelly',

              @v_UserMessage        = 'We have issues'

END

GO

 

--run just one unit test alone to verify results

--note that we will explicitly use transactions

--because we run unit test outside of the DBTestDriven framework

BEGIN TRAN

EXEC UT_USERTESTS_AddNewUserK

ROLLBACK

GO

 

See Also