Multiple stub calls

Component Testing for C

For a large number of calls to a stub, use the following syntax for a more compact description:

<call i> .. <call j> =>


You can describe each call to a stub by adding the specific cases before the preceding instruction, for example:

<call i> =>


<call i> .. <call j> =>


The call count starts at 1 as the following example shows:


 FAMILY nominal

 COMMENT Reading of 100 identical lines


 VAR file1, init = "file1", ev = init

 VAR file2, init = "file2", ev = init

 VAR s, init == , ev = 1

 STUB open_file 1=>("file1")3

 STUB create_file 1=>("file2")4

 STUB read_file 1..100(3,"line")1, 101=>(3,"")0

 STUB write_file 1..100=>(4,"line")1

 STUB close_file 1=>(3)1,2=>(4)1

 #s = copy_file(file1,file2);



Multiple stub calls

If a stub is called several times during a test, either of the following are possible:

The following example rewrites the test to use this syntax for the call to the STUB close_file:

STUB close_file (3)1

STUB close_file (4)1

No stub calls

To check that a STUB is never called, even if an ENVIRONMENT containing the STUB is used, use the following syntax:

STUB write_file 0=>(4,"line")

No testing of the maximum number of stub calls

If you do not want to test the maximum number of calls to a stub, you can use the keyword others in place of the call number to describe the behavior of the stub for the calls to the stub that are not yet described.

The minimum number of calls to a stub is checked against the maximum call number that is specified without the others keyword.

For example, the following instruction lets you specify the first call and all the following calls without knowing the exact number. In this example, the test checks that the stub has been called at least once:

STUB write_file 1=>(4,"line")1,others=>(4,"")1