Branch Coverage Testing in Software programming



What is Branch Coverage Testing

No software application can be written in a continuous mode of coding, at some point we need to branch out the code in order to perform a particular functionality. Branch coverage testing helps in validating of all the branches in the code and making sure that no branching leads to abnormal behavior of the application.

Test requirements and coverage measure

Branch coverage is best described in terms of test requirements and coverage measure. The test requirements for branch coverage are the branches of the program. In other words, the goal of this coverage is to execute all of the branches in the program. On the other hand, coverage measure is defined accordingly as the number of branches executed by your test cases over the total number of branches in the program. Branches are the outgoing edges from a decision point. Therefore, an if statement or a switch statement.

However, 100% coverage does not provide any guarantee of finding the problems in the code.

The fact that by testing more thoroughly we have more chances of finding a problem in the code. But it doesn’t matter which kind of coverage we utilize and how much coverage we achieve. There’s always a chance that we might miss something.

Branch coverage vs statement coverage

When these two metrics are involved, it’s of a high importance to talk about test criteria subsumption. One test criterion subsumes another criterion when all the tests widths that satisfy those criteria will also satisfy the other one. This is found between branch and statement coverage.

If we identify a test width that achieves 100% branch coverage, the same test width will also achieve, necessarily, 100% statement coverage. That’s what happens in general because branch coverage is a stronger criterion than statement coverage. There is no way to cover all the branches without covering all the statements. It’s not true that any test result satisfies statement coverage will also satisfy branch coverage.

The Conclusion

In general, it’s more expensive to achieve branch coverage than to achieve statement coverage, because achieving  branch coverage requires the generation of a larger number of test cases.

So what this relation means is that branch coverage is stronger than statement coverage, but also more expensive.

branch-coverage-testing

Pdf tutorials