Writing Test Script that is Easy to Understand & Maintain

The primary goal of using certain conventions while writing test scripts is to increase clarity & simplicity of source code. Consistency among all projects will allow other developer to understand the code regardless of who developed the code.

I like to think the whole program through at a design level before I sit down and write any of the code…. The really great programs I’ve written have all been the ones that I have thought about for a huge amount of time before I ever wrote them…. Part of our strategy is getting the programmers to think everything through before they go to the coding phase. Writing the design document is crucial…. The worst programs are the ones where the programmers doing the work don’t lay a solid foundation…. I really hate it when I watch some people program and I don’t see them thinking.

—Bill Gates

Let’s see what we can do to write code that is easy to understand & maintain:

1. Variable Names

  1. Use camel case for variables names.
  2. The first letter of a variable name should be lowercase and the first letter of each subsequent concatenated word should be capitalized.
  3. The first letter should show the data type as below
  • b – boolean, Boolean
  • c – char, Character
  • y – byte, Byte – b is used for boolean
  • h – short, Short –
  • i – int, Integer
  • l – long, Long
  • f – float, Float
  • d – double, Double
  • s – String

String sEmpState

String sEmpZipcode

Boolean bIsDisplayed

2. Constant Names

Use full English words in upper case letter with an underscore between the words.

Example: TAX_RATE

3. Method Names

  • Use full names that describe what the method does instead of using acronyms.
  • Method names should use a verb followed by a noun.
  • The first letter should be lower-case in method/function names and each subsequent word in names should begin with an upper-case letter

enterFormDetails ()


  • Use ‘is’ for methods that return booleans (e.g. isValid(), isEmpty())

4. Class and Interface Names

  • The name should begin with a noun.
  • Use simple and descriptive names.
  • Try not to use acronyms, unless they are universally acceptable. If you use one, document the full name in the class comments.
  • The first letter should be upper-case in classes/interfaces names and each subsequent word in names begins with an upper-case letter
Example: OpenUserAccount
  • Use the singular term
Example: CustomerList (not Customers)

5. Use fixed Prefixes for GUI object names:

  • btn – Button
  • chk – CheckBox
  • cmb – ComboBox
  • lbl – Label
  • lst – List
  • mnu – MenuBar
  • mni – MenuItem
  • opt – OptionPane
  • pnl – Panel
  • rad – RadioButton
  • tbl – Table
  • tbh – TableHeader
  • txa – TextArea
  • txt – TextField
  • txp – TextPane
  • tlb – ToolBar
  • tlt – ToolTip
  • tre – Tree




6. Working with Conditional Statements

  • Add comments to an if statement especially for nested If’s to make it easily understandable and manageable.

7. Working with loops

  • Each control statement should have an explanation of its purpose and the expected results.
  • Each loop, especially those used for reading records from data sheets should provide details at the beginning about loop logic.

8. Keywords

  • Decide some basic principle to name the keywords in Keyword-Driven Testing.
  • Decide on Vocabulary and Phrases – One of your first tasks should be to decide on the Verbs you want to handle in your application and your domain.
  • If there are multiple application areas being handled, it is better to have each type of keyword under its own section.


  • If possible don’t mix Comment and code in the same line. If a comment is on the same line, it should precede the statement.
  • Keep the length of the commenting line to the length permitted by the screen.
  • As far as possible, do not spread the comment across multiple lines. Each commenting line should be self-contained.
  • Use Javadoc comments at the start of each class & method to provide short detail about the purpose.
/** ***************************************************************
Functionality :

Created by :

Date created : 
Change History

Date Modified :          Modified By :        Comments :

10. Additional Guidelines:

For additional coding guidelines and recommendations please reference the following:

Article written by

Please comment with your real name using good manners.

Leave a Reply