Kokozaurus
Kokozaurus

Reputation: 639

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?

Upvotes: 1

Views: 180

Answers (1)

Kokozaurus
Kokozaurus

Reputation: 639

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.

Upvotes: 1

Related Questions