MOCK is a replacement of the original stored procedure that allows user to inject-new and override existing functionality without explicitly introducing changes to existing database code. MOCK procedure will have following qualities:

  • mock will have same signature and the same name as original procedure, including parameter default values and direction for output parameters
  • the original procedure will be renamed with unique name and preserved in the database, new procedure name can be found inthe DBTD_TBL_PRETEND_OBJECT table Original Name column
  • mock will have the same name as original procedure
  • MOCK can be configured to run SQL code from original stored procedure or substitute an old code with new one that can be executed: BEFORE, AFTER or INSTEAD-OF an original procedure code
  • mock will record information about each procedure call, together with the supplied parameter values for each individual procedure execution. Data will be stored in the DBTD_TBL_PRETEND_OBJECT_LOG and DBTD_TBL_PRETEND_OBJECT_PARAM_LOG tables
  • error occur if database does not have original procedure with the name specified in the v_ProcName parameter
  • DBTestDriven framework will truck stub execution for each individual unit test run



  • When stub or mock procedures created in the unit tests DB Test Driven framework will use transaction in the same way as if you will specify DBTD_USE_TRANSACTION hint 
  • Creating stub and mock procedures available only in SQL Server version of the framework 
  • Use DBTD_RESTORE_ORIGINAL_PROC procedure to restore mocked object to its original source code



  • v_ProcName - The name of the procedure to create MOCk or clone. This can be fully qualified name with database.schema.object. Parameter type SYSNAME.
  • v_BeforeSQL - unicode string that contains a Transact-SQL statement that will be executed before the original code.Parameter type NVARCHAR(MAX). Default value NULL.
  • v_InsteadOfSQL - unicode string that contains a Transact-SQL statement that will be executed instead of original code.Parameter type NVARCHAR(MAX). Default value NULL which specifies that no code will be executed.
    To automatically execute original code assign 'RUN ORIGINAL CODE' value to this parameter.
  • v_AfterSQL - unicode string that contains a Transact-SQL statement that will be executed after the original code.Parameter type NVARCHAR(MAX). Default value NULL.

Note: SQL Server only


SQL Server

       --this example will create teh MOCK object
       --which executes original code
       --for sp_AddNewProduct procedure and select
       --number of products before and after

                          @v_ProcName  = 'sp_AddNewProduct',
                          @v_BeforeSQL = 'SELECT COUNT(*) AS [Number Of Products Before]
                                                         FROM PRODUCTS',
                          @v_InsteadOfSQL = '
                          @v_AfterSQL  = 'SELECT COUNT(*) AS [Number Of Products After]
                                                        FROM PRODUCTS'

       --this example will create MOCK object that does not
       --call any of the original
       --functionality from sp_AddNewProduct

                          @v_ProcName  = 'sp_AddNewProduct',
                          @v_BeforeSQL = NULL,
                          @v_InsteadOfSQL = NULL
                          @v_AfterSQL  = NULL


See Also