background image
<< Modifying Stub Variable Values | Replacing Stubs >>
<< Modifying Stub Variable Values | Replacing Stubs >>

Stub Usage

Automated Testing
DEFINE STUB file
#int fic_errno;
#char fic_err_msg[100];
#int open_file(char _in f[100]);
#int create_file(char _in f[100]);
#int read_file(int _in fd, char _out l[100]);
#int write_file(int fd, char _in l[100]);
#int close_file(int fd);
END DEFINE
The global variables are created as if they existed in the simulated file.
Stub Usage
Use the STUB statement to declare that you want to use a stub rather than the
original function. You can use the STUB instruction within environments or test
scenarios.
This STUB instruction tests input parameters and assigns a value to output
parameters each time the simulated function is called.
The following information is required for every stub called in a scenario:
·
Test values for the input parameters
·
Return values for the output parameters
·
Test and return values for the input/output parameters
·
Where appropriate, the return value of the called stub
Example
The following example illustrates use of a stub which simulates file access.
SERVICE copy_file
#char file1[100], file2[100];
#int s;
TEST 1
FAMILY nominal
ELEMENT
VAR file1, init = "file1", ev = init
VAR file2, init = "file2", ev = init
VAR s, init == , ev = 1
STUB open_file ("file1")3
STUB create_file ("file2")4
STUB read_file (3,"line 1")1, (3,"line 2")1, (3,"")0
STUB write_file (4,"line 1")1, (4,"line 2")1
STUB close_file (3)1, (4)1
#s = copy_file(file1, file2);
END ELEMENT
END TEST
END SERVICE
The following example specifies that you expect three calls of
foo
.
STUB STUB1.foo(1)1, (2)2, (3)3
...
145