What is Branch Coverage Testing ?
Branch Coverage is a white box testing method in which every outcome from a code module(statement or loop) is tested. The purpose of branch coverage is to ensure that each decision condition from every branch is executed at least once. It helps to measure fractions of independent code segments and to find out sections having no branches.
It uses a control flow graph to calculate the number of branches.
Branch Coverage = Total number of Branch Executed
/ Total No of Branches
Branch Coverage is sometimes also described as saying that each branch condition must have been true at least once and false at least once during testing.
To learn branch coverage, let’s consider the below example
IF A+B > 50 THEN
If A+B<50 THEN
Flow Chart of Above Code
To calculate BranchCoverage, We have to find out the minimum number of paths so that all the edges are covered.
First Case : traversing through “Yes “decision, the path is 1-2-4-5-6-8 but edges 3 and 7 are not covered in this path.
Second Case :To cover the edges 3 & 7 as these are not covered in first step, we have to traverse through “No” decision. In the case of “No” decision the path is 1-3-5-7,
So by traveling through these two paths, all branches have covered.
Hence BranchCoverage is 2.
The main purpose of the Branch Coverage Testing is to make sure every functional test scenario has the ability to cover all the potential branching for functional looping statements.
Branch Coverage Testing is used to make sure that all the branches in the code are directed to the essential functional requirements mentioned in the application requirement specification provided by the client or the business stakeholders.
Reference : click on this link