How to call ATEasy procedures dynamically based on Test and Task names

Knowledge Base Article # Q200193

Read Prior Article Read Next Article
Summary Calling Initialize procedures based on a Test's name
  
Login to rate article
Sometimes it is useful to call a procedure with a function pointer. One example would be calling a unique procedure for each Test defined in a Program based on the Test and Task name of the current Test being executed. A procedure pointer can be used instead of hard coding a call to each procedure, thereby simplifying the code and allowing more tests to be added without code modification.

The following steps should be followed:
  • Create procedures for each test defined in the program. In this example, the procedure names must be the Task name followed with the underscore character, appended to the Test name follwed by “_Init”. This naming template can be changed by modifying the first line of code in step 3.
IDE Integrated Development Environment
  • Define a variable in the OnInitTest() event named proc of type Procedure. This will act as the function pointer.
  • Insert the following code in the OnInitTest() event.
proc=Task.Name+"_"+Test.Name+"_Init" !Assign the procedure pointer a procedure
if(proc)         !Check to make sure the procedure actually exists
     proc()      !Execute procedure
else
     print "proc is not valid!"
     !error handling code
endif

Article Date 5/19/2010
Keywords ATEasy, Procedures, Functions, Procedure Type, Test, Task


Login to rate article

1 ratings | 5 out of 5
Read Prior Article Read Next Article
>