I would like to ask what does “covering all statements” and “covering all branches” mean and the difference between those.
I could come up with the solution but I don’t what those expressions really mean.
Thank you for the message. I read it but I could not understand properly.
If we want to express informally those definitions; how would it be?
I could express “Statement Coverage” as follows; line being executed at the test case. That is to say, if we are writing a test case for covering all statements, the test suite we write should execute every line in the function we are testing. (I might be mistaken, would be glad if there is a better explanation)
But I could not come up with an informal expression of “Branch Coverage”. What does covering all branches and particularly branch mean? I would be glad if you can help me with that.
Yes, you want to cover all statements (and nested statements).
For instance, full statement coverage would need to also cover line 3 in Remark 7.3.6.
Usually, it is not possible to achieve full statement coverage with only one test case. As you probably noticed in your Java projects, you need many test cases to cover all possibilities that lead to different statements.
At certain instructions, the control flow of programs can take a branch.
For instance, for conditionals, you can either take the consequence or alternative.
You are usually interested in covering the possible cases of your program.
Therefore, you want a full branch coverage that guarantees that you took each branch (at least once the consequence and once the alternative).
If you covered all branches, you also covered all statements in these branches. Therefore, branch coverage implies statement coverage.
What would be an example of having all statement coverage while not having all branch coverage - if its possible ?
Particularly, I guess, at the example above, we cannot extend the test suite for covering all branches since when we do the a part, we basically get done for the second part. Because, there is no alternative (“else part”) for statement else if (x == 2) . We just continue from there with return statement but apparently it is not the case for the solution.