Procedure calculates the code coverage statistics and saves result in to the set of temporary statistical tables.

NOTE: This procedure should be executed after all unit tests has run. In many project configurations not all unit test run at the same time, there might be a need to collect statistics for longer intervals of time before checking for coverage. 

Arguments

  • v_DatabaseName -  The name of the database for which code coverage statistics are calculated. SYSNAME data type.
  • v_DisplayLevel -  statistics display level, VARCHAR(100)
    • ALL - populates coverage statistic information into set of temporary tables and select all data from all the statistical tables
    • RunSilent - populates coverage statistic information into set of temporary tables, but does not produce any output
    • HTMLCoverageReport - populates coverage statistic information into set of temporary tables and returns single recordset with one record and one column named HTMLCoverageReport, the column will contain HTML document with all available information for specified database. 

 

Stat Tables 

#Statistics

table contains general statistics information

Column Name Data Type Description
StatName VARCHAR(500) Name of the statistics attribute
StatValue VARCHAR(500) Value of the statistics attribute
StatMetrics VARCHAR(100) Name of the metrics, like % or number
SortOrder INT Sort order for display purpose
 
CREATE TABLE #Statistics(
    StatName VARCHAR(500),
    StatValue VARCHAR(500),
    StatMetrics VARCHAR(100),
    SortOrder INT
)
 
#StatisticsByObjectType

table contains coverage statistics by object type

Column Name Data Type Description
ObjectType VARCHAR(250) Object Type value as it specified in the sys.objects system table type_desc column
NumberOfObjects INT Total number of object of a given type in the target database
NumberOfCoveredObjects INT Number of covered object of a given type in the target database
NumberOfNotTestedObjects INT Number of object of a given type in the target database that are not tested 
NumberOfExceptions INT Number of exceptions of a given type for the target database
CoveragePercent NUMERIC(10,4) Code coverage percentage
 
CREATE TABLE #StatisticsByObjectType(
    ObjectType VARCHAR(250),
    NumberOfObjects INT,
    NumberOfCoveredObjects INT,
    NumberOfNotTestedObjects INT,
    NumberOfExceptions INT,
    CoveragePercent NUMERIC(10,4)
)
 
#CoverageExceptions

table contains list of coverage exceptions specified for a given database. Please use DBTD_ADD_CODE_COVERAGE_EXCEPTION to add exceptions. 

Column Name Data Type Description
ObjectName SYSNAME Name of the object
ObjectDatabaseName SYSNAME Database to which this object belong
ObjectSchemaName SYSNAME Schema to which this object belong
ObjectType VARCHAR(250) Object Type value as it specified in the sys.objects system table type_desc column
ExceptionDescription VARCHAR(500) Exception description
 
CREATE TABLE #CoverageExceptions(
    ObjectName SYSNAME, 
    ObjectDatabaseName SYSNAME, 
    ObjectSchemaName SYSNAME, 
    ObjectType VARCHAR(250),
    ExceptionDescription VARCHAR(500)
)
 
#CoverageDetails
 
table contains detailed coverage information related to all known objects from the target database. Raw information is collected by framework runners in the detailed test results table DBTD_TBL_TESTRESULT_DETAILS 
Column Name Data Type Description
ObjectID BIGINT Object identification number, as it specified in the sys.objects system table object_id column
ObjectName SYSNAME Name of the object
ObjectDatabaseName NVARCHAR(128) Database to which this object belong
ObjectSchemaName NVARCHAR(128) Schema to which this object belong
ObjectFullName NVARCHAR(128) The full object name. MyDB.MySchema.MyObject
ObjectType VARCHAR(250) Object Type value as it specified in the sys.objects system table type_desc column
UnitTestName NVARCHAR(128) The name of the unit test where this object were used
UnitTestRunID BIGINT Unique unit test run ID
CallingProcName NVARCHAR(128) name of the assert that verified this object
IsMSShipped BIT Reserved
Comments NVARCHAR(500) Reserved
 
CREATE TABLE #CoverageDetails(
    ObjectId BIGINT,
    ObjectName SYSNAME,
    ObjectDatabaseName NVARCHAR(128),
    ObjectSchemaName NVARCHAR(128),
    ObjectFullName NVARCHAR(128),
    ObjectType VARCHAR(250),
    UnitTestName NVARCHAR(128),
    UnitTestRunID BIGINT,
    CallingProcName NVARCHAR(128),  
    IsMSShipped BIT,  
    Comments NVARCHAR(500)
)
 
#AssertedObjects
 
table contains the list of all asserted objects in the target database 
Column Name Data Type Description
ObjectID BIGINT Object identification number, as it specified in the sys.objects system table object_id column
ObjectName SYSNAME Name of the object
ObjectDatabaseName NVARCHAR(128) Database to which this object belong
ObjectSchemaName NVARCHAR(128) Schema to which this object belong
ObjectFullName NVARCHAR(128) The full object name. MyDB.MySchema.MyObject
ObjectType VARCHAR(250) Object Type value as it specified in the sys.objects system table type_desc column
 
CREATE TABLE #AssertedObjects(
    ObjectId BIGINT,
    ObjectName SYSNAME,
    ObjectDatabaseName NVARCHAR(128),
    ObjectSchemaName NVARCHAR(128),
    ObjectFullName NVARCHAR(128),
    ObjectType VARCHAR(250)
)
 
#DatabaseObjects
 
table contains the list of all database objects from the target database 
Column Name Data Type Description
ObjectID BIGINT Object identification number, as it specified in the sys.objects system table object_id column
ObjectName SYSNAME Name of the object
ObjectDatabaseName NVARCHAR(128) Database to which this object belong
ObjectSchemaName NVARCHAR(128) Schema to which this object belong
ObjectType VARCHAR(250) Object Type value as it specified in the sys.objects system table type_desc column
 
CREATE TABLE #DatabaseObjects(
    ObjectID INT,
    ObjectName SYSNAME,
    ObjectSchemaName NVARCHAR(128),
    ObjectDatabaseName SYSNAME,
    ObjectType VARCHAR(100)
)
 
#UntestedObjects
table contains the list of all untested database objects in the target database 
Column Name Data Type Description
ObjectID BIGINT Object identification number, as it specified in the sys.objects system table object_id column
ObjectName SYSNAME Name of the object
ObjectDatabaseName NVARCHAR(128) Database to which this object belong
ObjectSchemaName NVARCHAR(128) Schema to which this object belong
ObjectType VARCHAR(250) Object Type value as it specified in the sys.objects system table type_desc column
 
CREATE TABLE #UntestedObjects(
    ObjectID INT,
    ObjectName SYSNAME,
    ObjectSchemaName NVARCHAR(128),
    ObjectDatabaseName SYSNAME,
    ObjectType VARCHAR(100)
)

 

 

Examples

SQL Server

In the first example checks code coverage for MyWarehouse database and displays results: 

        --*************************************************************************
        -- (A) calculate statistics and show results
        EXEC DBTD_Statistics  @v_DatabaseName 'MyWarehouse', @v_DisplayLevel = 'ALL';
        GO

In the second example statistics are running against same MyWarehouse database, but instead of all data we display only the targeted information about untested objects: 

         --*************************************************************************
         -- (B) calculate statistics and capture untested objects info

         CREATE TABLE #UntestedObjects(
 
            ObjectID INT,  
             ObjectName SYSNAME
             ObjectSchemaName NVARCHAR(128), 
             ObjectDatabaseName SYSNAME,
             ObjectType VARCHAR(100)

         );

         EXEC DBTD_Statistics @v_DatabaseName 'MyWarehouse';
         
         SELECT * FROM #UntestedObjects; 

 

See Also