Sunday, March 20, 2011

QTP Best practices

1. Use comments liberally. It is helpful in every section to identify what is being done and how you intend to do it. This makes it much easier for other people to understand what the test intends to do.

2. FN, LN etc are not good variable names. Absolutely avoid the use of such variable names as i, j, k.

3. It is always a good idea to define your variables at the top of your test and specify what type of data you intend to store into them.

4. Use mixed case or camel case for naming the variables. It becomes easy to read the variables.
E.g.
Dim strFirstName 'Stores the name
4. The Msgbox function should absolutely never be in a test. An automated test is designed to run with unattended execution. Using this function pauses the test and waits for user interaction. If you want to preserve log messages during your test, try the Reporter.ReportEvent method.

5. Never use the Inputbox function in a test. Your data should always be either

  • Hard-coded - Simple but not flexible
  • Parameterized - Best option since your datatable is editable through any spreadsheet tool.

6. Always indent your code. The interpreter does not care if you don't indent but humans do. Don't forget that during the lifetime of your code, someone else may be charged with updating it. Without proper indentation, it is difficult to figure out what the code below is doing:
Do while SomeCondition
If TestCondition=1 Then
MsgBox "Passed-1"
If TestCondition=2 Then
MsgBox "Passed-2"
End If
Else
MsgBox"Failed"
End If
Loop
The following is easier to read:
Do While SoneCondition

   If TestCondition=1 Then

      MsgBox "Passed-1"

      If TestCondition=2 Then

         MsgBox "Passed-2"

      End If

   Else

      MsgBox"Failed"

   End If

Loop

2 comments:

  1. nice topics ...........its help every one

    ReplyDelete
  2. Everything is fine, am happy about your blog. Thanks admin for sharing the unique content, you have done a great job.

    ReplyDelete

Please leave your comment here...