Sie sind auf Seite 1von 8

SQL Code Coverage for Test Coverage

Author(s): (1) Padamati Maheshwar Reddy

Written On: June 11, 2008

Declaration

I hereby declare that this document is based on my personal experiences and


experiences of my project members. To the best of my knowledge, this
document does not contain any material that infringes the copyrights of any
other individual or organization including the customers of Infosys.

Padamati Maheshwar Reddy

Project Details:

• Projects Involved: Role Guide (MSIVAITF)


• Project Type: Enhancement and Application Support

Target readers: All (Developers and Testers)


Introduction:

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.

Test Coverage Process:

After installing the SQL CC the below process needs to be


performed

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.

Creating the Config File.

1. After installation go to <Directory where the tool is installed>\Microsoft Sql Code


Coverage\Tools
2. Double click on the SqlccInstrumentWizard.exe
3. It will open
4. Provide the details as

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.

5. Provide all the required information and click on next


6. Enter the server name of the reporting server and click on add server
7. The server name will be listed in the list below
8. Select the appropriate server if more than 2 and click on next

9. Select the appropriate database and click on next

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.

By this the process of creating of the config file is completed.

Instrument and save coverage data

To instrument the code use the following command from the command prompt:

SQLCCInstrument –c < config file >

< config file > -- Name including the path

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

Creating the trace

For creating the trace use the following command from the command prompt:
Create a trace: SQLCCTrace –c < config file > -Create < tracename >

< config file > -- Name including the path


< tracename > -- Name of the trace

Starting the trace

For starting the trace use the following command from the command prompt:
Start a trace: SQLCCTrace –c < config file > -Start < tracename>

< config file > -- Name including the path


< tracename > -- Name of the trace

Stopping the trace

For stopping the trace use the following command from the command prompt:
Stop a trace: SQLCCTrace –c < config file > -Stop < tracename >

< config file > -- Name including the path


< tracename > -- Name of the trace

Closing the trace


For closing the trace use the following command from the command prompt:
Close a trace: SQLCCTrace –c < config file > -Close < tracename >

< config file > -- Name including the path


< tracename > -- Name of the trace

Uninstrument the trace

To uninstrument the code, use this command:


SQLCCInstrument –c <config file> -u

< config file > -- Name including the path

Import the trace

To import the trace data to the Reporting DB:


SQLCCImport –c <config file> -i <tracefile> -as <trace filename>

< config file > -- Name including the path


< tracename > -- Name of the trace
<trace filename> -- Name for the trace file imported

Generate a report

To generate a report use the command


SQLCCReport -c <config-file>

< config file > -- Name including the path

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).

WHERE RGtbCareerStages.CSShortName IS NOT NULL


AND RGtbRoleCareerStageCourses.RGtbRoleID = @RoleID
AND RGtbRoleCareerStageCourses.RGtbRoleST = 1
AND RGtbRoleCareerStageCourses.RGtbCourseID = @CourseID
AND RGtbRoleCareerStageCourses.RGtbCourseST = @CourseST
FOR XML PATH('')
)

--To remove the last comma in the career stage name


SET @CareerStageName = LEFT(@CareerStageName,(LEN
(@CareerStageName) - 1))

IF @CareerStageName IS NOT NULL


BEGIN
SET @CareerStageName = @CareerStageName
END
ELSE
BEGIN
SET @CareerStageName = NULL
END
END
ELSE
BEGIN
SET @CompleteByDate = NULL
SET @AssignedBy = NULL
SET @CompetencyName = NULL
SET @CareerStageName = NULL
END

--Select query to be displayed in the UI


SELECT DISTINCT
REPLACE (CONVERT (nvarchar, @CompleteByDate,106), '01 Jan
1900', '' ) AS CompleteByDate
,AssignedBy = @AssignedBy
,[CompetencyName] = @CompetencyName
,[CareerStageName] = @CareerStageName
,[EntityCode] = 'xxxx' --This is not used in UI, but due to code
resure in LR and Search have implemented this
,[RGtbCourseID] = RGtbCourses.RGtbCourseID
,[RGtbCourseST] = RGtbCourses.RGtbCourseST

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.

1. Test cases to be modified see if proper operations on the UI are performed


2. Missing test cases if any to be included

Das könnte Ihnen auch gefallen