Search code examples
callbackautomationsilktest

How to use callback function in SilkTest's 4Test language


So I'm trying to use something ancient like the 4Test language in SilkTest in a somewhat modern manner. I have several similar tests which differ in only a part of the code. I would like to create an infrastructure function which would do the boilerplate stuff and then just call different functions for different tests. Like a callback function let's say.

So I would like to do something like that:

testcase A(Function F)
    do some stuff
    F()
    do other stuff

Has anyone done this? How should I do it?


Solution

  • So I have found a solution and I'm posting it here for documentation reasons.

    When a person wants to pass a function as an argument, they have to pass the name of the function as string, and then call it with the following structure

    @(functionNameString)()
    

    So the code would be like

    void someFunction()
        Print("Hello World!")
    
    @("someFunction")()
    

    This also works with methods of objects.