What is meant by “every branch” in testing coverage criteria?
https://softwareengineering.stackexchange.com/questions/372020
-
06-02-2021 - |
Domanda
I have generated the program graph of a method that contains an if
condition and a for
loop, and I need to generate test cases that covers "every branch". Would this include the for
loop, given that program graphs are abstractions of the actual code, and the for
loop does cause there to be two separate paths in the program graph?
public int void randMethod(int num) {
for (i = 0; i <= 1; i++) {
if (num == 1) {
num--;
} else {
...
}
}
....
}
Could you cover all branches with a single test case, i.e. where the num
input == 1?
Soluzione
Yes, why would it not?
Note that the for loop case is often a triviality, you just make sure that one of your test cases is such that the loop executes at least once and terminates, job done.
The same thing applies to a while loop and to any other loop type constructs you may have.