Test Partner does not return a compile error for undeclared variables

0 Likes
over 9 years ago

In Test Partner, if I have an undeclared variable why is an error not returned when compiling the project.


For example the following should return an error when compiling:

By default, VBA doesn't require that you declare your variables using the Dim statement. If the compiler encounters a name that it doesn't recognise as an existing variable, it will create a new variable of Variant type.

You can prevent this by requiring that all variables be declared. At the first line of code in the Shared module or Test Script, above and before any other lines, use: "Option Explicit". This statement requires that all variables be declared using a Dim statement. Using the above code example, Test Partner will return a compile error if Option Explicit is used:

You can set an option in the VBA Editor that will automatically add an Option Explicit directive in all newly created Test Scripts or modules. For any existing Test Scripts or modules, this oprion must be added manually.

In Test Partner, go to the Tools menu, choose Visual Basic Options and then select the Editor tab.
There, check the Require Variable Declaration option. 

Tags:

Labels:

How To-Best Practice
Comment List
Anonymous
Related Discussions
Recommended