Test Design StudioGo to Previous Topic: Syntax CheckingGo to Next Topic: Static Analysis Rules

Static Code Analysis

Note:   This feature is currently only available on VBScript-based files like those used by Unified Functional Testing.

Static Code Analysis

Static code analysis is the analysis of code that is performed without actually executing the logic represented by the code. Syntax checking will ensure you follow the rules of the language, but does not ensure you are using it properly. If you have ever received a run-time error while executing scripts in Unified Functional Testing, you have fallen victim to code that, while having the proper syntax, is being used improperly.

Test Design Studio seeks to drastically reduce or eliminate run-time errors!

To illustrate how many errors can exist in Unified Functional Testing that are not reported by the syntax checker, analyze the following code. You can even load this code in Unified Functional Testing and perform a syntax check to verify that it will report the syntax is correct. How many errors have to be fixed before this simple block of code can run?

[VBScript] - Copy Code
Dim sMessage

Option Explicit

sMessage = "Hello World"
MsgBox sMessage, OkOnly

If Browser("index:=0").Exist(0) = True Then
  bItemIsValid = True
Else
  bItemIsValid = False
End If

Dim sMessage
sMessage = "Item is Valid = " & Str(bItemIsValid)
Reporter.ReportEvent micPass, sMsg

The following errors are present in this code (discussed in order of appearance):

  1. Duplicate declaration of the variable sMessage.
  2. Option Explicit must appear before all other code. In this sample, it follows a variable declaration.
  3. The MsgBox function is called with an invalid second argument. It should be vbOkOnly instead of OkOnly.
  4. The return value of Browser("index:=0").Exist(0) is being directly compared to True, which will result in incorrect evaluation of the result.
  5. Use of undeclared variable bItemIsValid when Option Explicit is set.
  6. The user is calling a non-existing function Str to try to convert a value to a string instead of CStr.
  7. Accidental use of undeclared variable sMsg when the user should have used sMessage.
  8. Incorrect number of arguments passed to Reporter.ReportEvent method.


Test Design Studio reports on each and every error mentioned above... and more!

The following screen shot from Test Design Studio shows errors underlined in red, and warnings underlined in green.

Test Design Studio does more than validate syntax, it analyzes your code for proper usage using a collection of pre-defined rules! Countless hours can be wasted tracking down the cause of run-time errors, and the worst place to encounter one of them is in the middle of a test execution. At that point, you have to roll back all the changes to your test environment just so you can start your test again and hope that no more run-time errors are lurking in the code. In the case of overnight or weekend tests, you may have lost your entire testing window!

Use Test Design Studio to identify those errors when it is most effective... at the time you write the code!

Note:   All of the errors and warnings reported by static code analysis are displayed in the Error List tool window.