Sunday 13 April 2014

Script Naming convention and Coding standards

1.0         Purpose

An automated test script can be viewed as a full fledged program. Hence, like any other program in C, C++, Java etc, this script/program would undergo review (CWT), modifications etc. For a person to review or modify it, it’s obvious that the person understands the script thoroughly and there are no confusions. For that, the script should strictly follow standards for naming and coding.

This document explains the standards to be followed for-

  1. Script header
  2. Naming:
    1. Script
    2. Code variables
    3. Data table variables (column headings)
    4. Test objects (in the Object Repository)
    5. Report output file
  3. Coding:
    1. Commenting
    2. Indentation
    3. Decision statements (IF)
    4. Loops (WHILE, FOR etc)
    5. Database querying

2.0         Script Header

The test script header should have following details:

‘Name of the script:                               <Name of the script>
‘Name of the application and/or module:            <Name of the application for which the test is being written>
'Author:                                                 <Name & of the Author>
'User id:                                                <Author’s CEC id>
'Created on:                                          <Date (dd-mon-yyyy) on which this code was created>
'Purpose:                                              <Why this piece of code has been written>
'Input:                                                   <What are the input parameters (if any)>
'Output:                                                            <What are the output or return parameters (if any)?>
‘Pre-conditions:                                     <What are user accesses required, desktop/QTP settings, Test environment specifics etc>
'Modified:                                             <1. Date Modified, Logic modified>
'                                                           <2. Date Modified, Logic modified>
                                                            .
                                                            .                                                            .
Note: Each place that you modify the code, please write the number as in modified and then write the code.

3.0         Naming standards

Following are the naming standards for the various entities-

3.1         Script

The script name should be in the format TestXXX and should follow a Hungarian notation.
E.g. TestMaxlengthValidations

3.2         Code variables

The code variables should be named based on the data type as below-
Boolean            bln        blnFound
Byte                 byt       bytRasterData
Date (Time)       dtm      dtmStart
Double             dbl       dblTolerance
Error                 err        errOrderNum
Integer              int         intQuantity
Long                 lng        lngDistance
Object              obj       objCurrent
Single               sng       sngAverage
String               str        strFirstName

3.3         Data table variables (column headings)

Inputs:
If a data table field is being used to store an input for a form, it should be named as “dt_in_<corresponding test object name>”.
E.g. if the form field <Template> has a corresponding test object (in the OR) as <Template>, the data table field should be named as “dt_in_Template”.

Expected results:
If a data table field is being used to store an expected result, which may output as a field value, static text or message, it should be named as “dt_out_<corresponding test object or form field name>”.

3.4         Test objects (in the Object Repository)

The test objects in the object repository should preferably be named as the corresponding form field names/labels. The names should follow Hungarian notation w/o any space.

3.5         Report output file

The report output file (Excel workbook) should be named as “report_<test script name>”.
The individual sheets in the workbook corresponding to the test cycles should be named as “Test Cycle#<cycle number>”.
E.g. the report file for the test script “TestMaxlengthValidations” should be named as “report_TestMaxlengthValidations”.

4.0         Coding standards

4.1         Commenting

Put descriptive comments at appropriate places to achieve following objectives:
·         A clear understanding of the logic
·         Ease for a person to understand and modify the code

4.2         Indentation

Indent the code appropriately and logically to understand the code flow.

E.g.
For counter = start To end [Step step]
    [statements]
    
   For counter = start To end [Step step]
    [statements]
    [statements]
                Next
   
    [statements]
Next

4.3         Decision statements

The decision statements like “IF”, “CASE” should be coded with following format-
        IF
 
        If condition Then
                               [statements]
               [ElseIf condition-n Then
                               [elseifstatements]] . . .
               [Else
                               [elsestatements]]
    End If

        CASE

        Select Case testexpression
                  [Case expressionlist-n
                     [statements-n]] . . .
                  [Case Else expressionlist-n
                     [elsestatements-n]]
   End Select

4.4         Loops

The loop statements like “WHILE” should be coded with following format-
      Do [{While | Until} condition]
               [statements]
               [Exit Do]
               [statements]
Loop

4.5         Database querying

In a scenario, where database querying is involved, following steps should be followed-

‘Create connection object
Set connectionObject = CreateObject("ADODB.Connection")
‘Create recordset object
Set recordSet = CreateObject("ADODB.Recordset")
‘Connect to the database
connectionObject.Open ("DSN=TEST;UID=<user id>;PWD=<password>;")
‘Fetch records
              While not recordSet.eof
                        tagId = recordSet("ID")
                        DataTable.SetCurrentRow(intRecordSetCounter)
                        recordSet.MoveNext
            .
            .
            .
Wend

No comments:

Post a Comment