YaST2 modules testsuite -- Creating tests


Creating tests

Creating tests is easy. You need to have your code ready (for example in some include file) and you need to know the input and output data.

Testing a function

Presume you have a function fun() in the include file routines.ycp. The function needs one argument -- string input and returns one argument -- string output.

We create a test case:

    {
        include "testsuite.ycp";
        include "your/routines.ycp";
        TEST(``(fun("input1")),[],nil);
        TEST(``(fun("input2")),[],nil);
        TEST(``(fun(nil)),[],nil);
    }
In this test case, we are testing a function fun with "input1", "input2" and nil as input parameters.

SCR calls

In the next test case we test a module (write only client). This shows also another possibility of TEST function usage -- not function, but client call.

In this example it is also shown how the system access is simulated in the testsuite. You define values which are returned upon the SCR call instead of the real agent call. Testsuite uses a dummy agent for this simulation, so syntax is same.

    {
        include "testsuite.ycp";
        include "your/routines.ycp";

        map READ = $[
            "x" : 1,
            "y" : $[ "a" : 2, "b" : 3 ]
        ];
        map WRITE = $[];
        map EXECUTE = $[
            "target": $[ "mkdir": true ]
        ];
        any DEFAULT = false;

        map DATA = $[ ... ];

        TEST(`module_write(DATA),[READ,WRITE,EXECUTE],DEFAULT);
    }
The READ, WRITE, EXECUTE and DEFAULT values are used only if the tested function uses SCR calls.

For example, SCR::Read(.x) returns 1. Other examples:

So, if your module reads string from the path .xhost.key, simply do:
    map READ = $[ "xhost" : $[ "key" : "some string" ] ];
    any DEFAULT = false;
    TEST(`your_module(DATA),[READ],DEFAULT);

Other examples

That's basically all what you need for creating testsuite. Look to other chapters, how to process the testsuite and use it daily.

You may want to take a look to some other modules for examples.
For instance: