This procedure adds code coverage exception record in to the ‚ÄčDBTD_TBL_CODE_COVERAGE_EXCEPTIONS table. Exception are excluded from code coverage analysis.

NOTE:For instance if database has 10 stored procedures, 8 of them are unit tested, while 2 are not. The stored procedure coverage is 80%, however if other 2 objects are obsolete and old stored procedures that are not used anywhere and scheduled to be dropped from the database, they can be added as an exception. Adding obsolete object exceptions will bump up code coverage to 100% 

Arguments

  • v_ObjectName - The name of the database object, value should contain name only without a schema or a database name . Parameter type SYSNAME.
  • v_ObjectDatabase - The name of the database to which this object belongs. Parameter type SYSNAME.
  • v_ObjectSchema - The name of the schema to which this object belongs. Parameter type SYSNAME.
  • v_ExceptionDescription - Detailed description of why this object should be excluded from code coverage analysis. Parameter type NVARCHAR(500).
  • v_ObjectType - The type of the object. Parameter type NVARCHAR(500). NULL is default value, that means any type of object with that name is excluded from coverage analysis. Otherwise use value specified in the sys.objects system table type_desc column for the object that need to be excluded, here are the values:
    • AGGREGATE_FUNCTION
    • CHECK_CONSTRAINT
    • CLR_SCALAR_FUNCTION
    • CLR_STORED_PROCEDURE
    • CLR_TABLE_VALUED_FUNCTION
    • CLR_TRIGGER
    • DEFAULT_CONSTRAINT
    • EXTENDED_STORED_PROCEDURE
    • FOREIGN_KEY_CONSTRAINT
    • INTERNAL_TABLE
    • PLAN_GUIDE
    • PRIMARY_KEY_CONSTRAINT
    • REPLICATION_FILTER_PROCEDURE
    • RULE
    • SEQUENCE_OBJECT
    • SERVICE_QUEUE
    • SQL_INLINE_TABLE_VALUED_FUNCTION
    • SQL_SCALAR_FUNCTION
    • SQL_STORED_PROCEDURE
    • SQL_TABLE_VALUED_FUNCTION
    • SQL_TRIGGER
    • SYNONYM
    • SYSTEM_TABLE
    • TABLE_TYPE
    • UNIQUE_CONSTRAINT
    • USER_TABLE
    • VIEW

Note: SQL Server only

Examples

SQL Server

As a pattern for your project , we usually recommend to save every database object in a separate file, this allows developers to keep all steps related to that object in one place, it provides ability to track changes to a code efficiently and minimize an impact to other parts of the code. In example below we have a unit test helper table that is added as a code coverage exception.  

--**********************************************************************************

USE TheOtherDB
GO

EXEC DBTestDriven.dbo.DBTD_DROP_TABLE_IF_EXISTS 'SOME_INDEXTABLE'
GO
 
--*****************************************************************************************
EXEC DBTestDriven.dbo.DBTD_ADD_CODE_COVERAGE_EXCEPTION
      @v_ObjectName = 'SOME_INDEXTABLE',
      @v_ObjectDatabase = 'TheOtherDB',
      @v_ObjectSchema = 'dbo',
      @v_ExceptionDescription = 'Unit Test Helper table, does not used anywhere besides UTs',
      @v_ObjectType= 'USER_TABLE'
GO
 
--*****************************************************************************************
--first create table 
CREATE TABLE SOME_INDEXTABLE
(
TempID int,
Name VARCHAR(255),
Note VARCHAR(255)
);
GO
 
--then  create test index
CREATE INDEX IX_SOME_INDEXTABLE_Name 
    ON SOME_INDEXTABLE (Name); 
GO
 
--note: SQL Server Specific 
--create clustered non unique test index
CREATE CLUSTERED INDEX IX_SOME_INDEXTABLE_TempID 
    ON SOME_INDEXTABLE (TempID); 
GO
 
--create unique index
CREATE UNIQUE INDEX IX_SOME_INDEXTABLE_Note 
    ON SOME_INDEXTABLE (Note); 
GO
 
 

See Also