Branch testing

Branch Testing/ Decision Coverage:

Test coverage criteria requires enough test cases such that each condition in a decision takes on all possible outcomes at least once, and each point of entry to a program or subroutine is invoked at least once. That is, every branch (decision) taken each way, true and false. It helps in validating all the branches in the code making sure that no branch leads to abnormal behaviour of the application.

Formula:

Branch Testing=(Number of decisions outcomes tested / Total Number of decision Outcomes) x 100 %


A branch is the outcome of a decision, so branch coverage simply measures which decision outcomes have been tested. This sounds great because it takes a more in-depth view of the source code than simple statement coverage, but branch coverage can also leave you wanting more.
Determining the number of branches in a method is easy. Boolean decisions obviously have two outcomes, true and false, whereas switches have one outcome for each case—and don't forget the default case! The total number of decision outcomes in a method is therefore equal to the number of branches that need to be covered plus the entry branch in the method (after all, even methods with straight line code have one branch).

Branch Testing Example



/**  Branch Testing Exercise
 *   Create test cases using branch test method for this program
 */
        declare Length as integer
        declare Count as integer
        READ Length;
        READ Count;
        WHILE (Count <= 6) LOOP
            IF (Length >= 100) THEN
                Length = Length - 2;
            ELSE
                Length = Count * Length;
            END IF
            Count = Count + 1;
        END;
        PRINT Length;






DecisionPossible Outcomes
Test Cases
12345678910
 Count  <= 6 T  X
 F X
 Length >= 100 T  X
 F


Test Cases

Case #Input Values
Count   Length
Expected OutcomesActual Outcomes
1 5       101 594
2 5       99 493
3 7       99 99
4

No comments: