testing - Branch Coverage for different kinds of loops -
i know if have if-statement so...
if (x == y) { foobar++; } else { if (x == z) { foobar++; } }
there 4 branches traverse in order 100% branch coverage. 2 outer if - else, 1 inner if statement , if doesn't go inner if statement.
however, this...
if (x == y) { foobar++; } else { while (x < z) { x++; } }
are there still 4 branches needed 100% branch coverage? is, not going while loop else statement count separate branch?
thank you.
first of all: there no if-loops. it's called if-statement.
as question: first example has 3 branches. first if
creates 2 branches. inside else
2 more branches created doesn't add 4 child branches of else
.
if / \ 1 else | if / \ 2 3
for branch coverage of while
loop gets little complicated. theoretically loop creates possibly infinte number of branches, don't know how or can run. there several practical approaches measure coverage of loops. simple 1 having 2 branches. 1 loop block executed, 1 isn't. in case still have 3 branches in example. there possibility consider 3 branches loop: not running, runnning once , running more once. if use such coverage measurement, have 4 branches in second example.
Comments
Post a Comment