Note: This feature is currently only available on VBScript-based files like those used by Unified Functional Testing.
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?
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):
Option Explicitmust appear before all other code. In this sample, it follows a variable declaration.
MsgBoxfunction is called with an invalid second argument. It should be
Browser("index:=0").Exist(0)is being directly compared to
True, which will result in incorrect evaluation of the result.
Option Explicitis set.
Strto try to convert a value to a string instead of
sMsgwhen the user should have used
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.