Posts Tagged making complex decisions

Misapprehension 4: It is clear how to measure coverage

Not always. In the following two figures two cases of doubt are shown; on the left hand side the software snippet in question and on the right hand side the coverage result of the module/unit testing tool Tessy.

How many branches are comprised by this switch instruction?

How many branches are comprised by this switch instruction?

The switch-instruction on the left hand side in the above figure could consist of two or of four branches. In the case of two branches, the labels “case 0”, case 1”, and “case 2” designate one and the same branch. This could be justified because all labels lead to the execution of the same instruction. In case of four branches, each label counts for a branch. The difference becomes obvious if a test case with “i == 1” is executed. Does this result in 25% or in 50% branch coverage? On the right hand side in the figure above the measurement of Tessy is displayed. It becomes clear that for Tessy, the switch-instruction consists of four branches; hence the test case in question results in 25% coverage. This can be justified because instead of the assignment “a = 700” e.g. “a = 1(2-i)” could be implemented. Then a test case with (i == 2) would result in a division be zero. Such a test case can be omitted easily, if the test case with (i == 1) yields complete coverage already.

How many branches are comprised by the question mark operator?

In a sense the question mark operator just selects between two values of which one is assigned to a variable. Does this comprise one or two branches? On the right hand side in the figure above the result of Tessy for a test case execution with (a > b) is designated. It becomes clear that for Tessy the question mark operator consists of two branches, of which one was executed by this test case, whereas the other was not. To justify this you can easily construct an example like above, where for instance an assignment “ret_val = 1/(ret_val-b)“ after the instruction with the question mark operator is assumed.

, , , , ,

No Comments