Checks that mock object DOES NOT exists in the database, verifies that that mock WERE NOT automatically created by the DBTestDriven Framework, and checks that there is not records in the DBTD_TBL_PRETEND_OBJECT table. Report failure any other case.

Arguments

  • v_PretendObjectName – Name of the mock object. Supports four part object name. SYSNAME data type.
  • 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 primary outer procedure*/

CREATE PROC SetupDefaultUsers

AS

BEGIN

       EXEC AddNewUser @UserName = 'Kelly',     @UserRole = 'Administrator'

       EXEC AddNewUser @UserName = 'Bill',      @UserRole = 'Reporting Team'

       EXEC AddNewUser @UserName = 'Michael',   @UserRole = 'Developer'

END

GO

 

/*Create unit test procedure. NOTE: This Unit Test will Fail !!!!! */

CREATE PROCEDURE UT_USERTESTS_AddNewUser

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_MOCK_PROCEDURE 'AddNewUser', NULL, NULL, NULL

       --assert that mock with given name not exists (and it does because

       --we have created it in the line before us)

       --so that next line will produce an error when you are running this unit test

       EXEC DBTD_ASSERT_MOCK_NOT_EXISTS

              @v_PrependObjectName  = 'AddNewUser',

              @v_UserMessage        = 'THIS Unit Test were written to intentionally fail'

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_AddNewUser

ROLLBACK

GO

 

See Also