SQL Code Coverage For Test Coverage
SQL Code Coverage For Test Coverage
Declaration
Project Details:
SQL Code Coverage tool helps identify critical bugs early on in the software lifecycle
of a SQL application by providing testers accurate and detailed measurement of their
test coverage. This tool integrates into the existing testing workflow with minimum
of intrusion and side effects to the source code thereby making it possible for all the
test cases to be run as is without making any changes to it.
Objective:
This tool is helpful in validating the store procedures which are newly created
or majorly modified. It can be used validating
1. Batch Jobs that are enhanced by adding new SP’s or Modifying the
existing SP’s
2. SP’s which are added or modified that are accessed from the UI
3. Refine the test cases created
4. Create new test cases after the analysis of the report and identifying
the areas that needs to be covered.
1. Create the config file which has the SP’s that are added newly or modified.
2. Instrumenting the config files
3. Creating the trace
4. Starting the trace
5. Stopping the trace
6. Importing the Data into reporting server
7. Generating the report.
Component Name
A component is the basic grouping used in SQL Code Coverage. There can be
only one component in a given configuration file. If you want to group your
application into several components use multiple configuration files. It is
highly recommended that you provide a name for the component which has
a logical relation with the application being tested.
Component Share
This is also called Component Share Directory and refers to the directory
path where you want the Component to be saved. Pathname should follow
the following pattern - \\machinename\sqlcc\components. This share
requires write access for the id running the SQLCC Tool commands. When
using Magellan Reporting the source code for all program units specified in
the component is stored in a text file under this share.
Custom Version
This is a string which you assign arbitrarily to group together the components
of a logical build. This is same as ‘Build Name’ used in SQLCC 2.5. The custom
version will be later used for identification purposes when importing and
reporting various builds.
Overwrite Component
This can be set to ‘true’ if the specified component already exists in the
reporting database and has to be overwritten. It is set to ‘false’ by default.
10. Select the required which had been modified or added new Sp’s and click on next
11. Provide the Reporting DB wherever you want to track the trace and import the data.
12. Save the location where the config file should be placed
13. Go to the location and check whether all the SPs required are included or not.
To instrument the code use the following command from the command prompt:
Before Instrumentation
CREATE procedure Sample1
as
declare @City as varchar
declare @CCount as int
@CCount = 0
if not exists(
select ‘x’
from CC_CustContact
where Cust_City = @City)
begin
select @CCount = 1
end
else
begin
select
@CCount = max(CCount) + 1
from
CC_CustContact
where
Cust_City = @City
end
After Instrumentation
CREATE procedure Sample1
as
declare @City as varchar
declare @CCount as int
@CCount = 0 /*
__SQLCodeCoverage__.Block(guid=1,sp_name=[dbo].[sample1],block_id=0); */
if not exists(
select ‘x’
from CC_CustContact
where Cust_City = @City)
begin
select @CCount = 1 /*
__SQLCodeCoverage__.Block(guid=1,sp_name=[dbo].[sample1],block_id=1); */
end
else
begin
select
@CCount = max(CCount) + 1
from
CC_CustContact
where
Cust_City = @City /*
__SQLCodeCoverage__.Block(guid=1,sp_name=[dbo].[sample1],block_id=2); */
end
For creating the trace use the following command from the command prompt:
Create a trace: SQLCCTrace –c < config file > -Create < tracename >
For starting the trace use the following command from the command prompt:
Start a trace: SQLCCTrace –c < config file > -Start < tracename>
For stopping the trace use the following command from the command prompt:
Stop a trace: SQLCCTrace –c < config file > -Stop < tracename >
Generate a report
SQLCC Reports
SQLCC color coded source code
The green part of the source code indicates the path traversed(Block Hits) and the red part
indicates path not traversed(Block Miss).
Conclusion:
Based on the above report team shall analyze what are the paths which did not hit. Following
are the checks that shall be performed.