Thursday 27 December 2012

How to calculate Statement, Branch/Decision Coverage



How to calculate Statement, Branch/Decision Coverage

HOW TO CALCULATE STATEMENT, BRANCH/DECISION AND PATH COVERAGE FOR ISTQB EXAM PURPOSE


Statement Coverage: (Find shortest path such that all nodes are covered at-least once)

In this, the test case is executed in such a way that every node is traversed at-least once.

Branch/Decision Coverage: (Find shortest path such that all the Edges are covered at-least once)

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 behavior of the application.



Path Coverage:(Find all the paths from source to destination)

In this the test case is executed in such a way that every path is executed at least once.
All possible control paths taken, including all loop paths taken zero, once, and multiple
(ideally, maximum) items in path coverage technique, the test cases are prepared based
on the logical complexity measure of a procedural design. In this type of testing every
statement in the program is guaranteed to be executed at least one time. Flow Graph,
Cyclomatic Complexity and Graph Metrics are used to arrive at basis path
How to calculate Statement Coverage, Branch Coverage and Path Coverage?

Draw the flow in the following way-
Nodes represent entries, exits, decisions and each statement of code.
Edges represent non-branching and branching links between nodes.

Example:
Read P
Read Q
IF P+Q > 100 THEN
Print “Large”
ENDIF
If P > 50 THEN
Print “P Large”
ENDIF
Calculate statement coverage, branch coverage and path coverage.




The flow chart is-



Statement Coverage (SC):

To calculate Statement Coverage, find out the shortest number of paths following
which all the nodes will be covered. Here by traversing through path 1A-2C-3D-E-4G-5H all
the nodes are covered. So by traveling through only one path all the nodes 12345 are covered,
so the Statement coverage in this case is 1.

Branch Coverage (BC):

To calculate Branch Coverage, find out the minimum number of paths which will
ensure covering of all the edges. In this case there is no single path which will ensure coverage
of all the edges at one go. By following paths 1A-2C-3D-E-4G-5H, maximum numbers of
edges (A, C, D, E, G and H) are covered but edges B and F are left. To covers these edges we
can follow 1A-2B-E-4F. By the combining the above two paths we can ensure of traveling
through all the paths. Hence Branch Coverage is 2. The aim is to cover all possible true/false
decisions.
Path Coverage (PC):
Path Coverage ensures covering of all the paths from start to end.
All possible paths are-
1A-2B-E-4F
1A-2B-E-4G-5H
1A-2C-3D-E-4G-5H
1A-2C-3D-E-4F
So path coverage is 4.
Thus for the above example SC=1, BC=2 and PC=4.
Memorize these….
100% LCSAJ coverage will imply 100% Branch/Decision coverage
100% Path coverage will imply 100% Statement coverage
100% Branch/Decision coverage will imply 100% Statement coverage
100% Path coverage will imply 100% Branch/Decision coverage
Branch coverage and Decision coverage are same.

Thanks,

Mohit Bhatia
View Mohit Bhatia's profile on LinkedIn

43 comments:

  1. Great !! Thank you

    ReplyDelete
  2. Very Helpful from one about to sit the ISTQB foundation level exam.

    ReplyDelete
  3. Thank you for simple and great help

    ReplyDelete
  4. Thank you, it helped me understand in easy way.

    ReplyDelete
  5. Thank you so much for simplifying this! It is great help for the one who is not from IT background. Keep it up!

    ReplyDelete
  6. According to ISTQB Foundation book Branch coverage is not same as decision coverage because branch coverage including all conditional and unconditional ,but decision coverage only including conditional

    ReplyDelete
  7. not applicable for all..

    ReplyDelete
  8. Thanx a lot, Please provide me more examlpe of coverege. Revert back me on mohit3021@gmail.com

    ReplyDelete
  9. Thanks for the explanation :)

    ReplyDelete
  10. Very good document to follow

    ReplyDelete
  11. Thank you, exactly an explanation I was looking for!

    ReplyDelete
  12. Very useful explanation with example.. thanks a lot

    ReplyDelete
  13. Very good and simplified manner to describe things...very good...keep it up....

    ReplyDelete
  14. Thank you! This is of great help!

    ReplyDelete
  15. Thanks a lot... I was totally confused. Now cleared

    ReplyDelete
  16. Thanks a lot :)

    ReplyDelete
  17. Thanks a bunch - sitting for this test in a couple of days and this was very helpful

    ReplyDelete
  18. IF A > B THEN
    C = A � B
    ELSE
    C = A + B
    ENDIF
    Read D
    IF C = D Then
    Print �Error�
    ENDIF
    sir how to find branch coverage and decision coverage for this problem

    ReplyDelete
    Replies
    1. Mahesh can you repost your example? I am getting �for operators

      Delete
    2. Hi Mahesh !
      I had the same question for ISTQB :D
      the missing operator on line 2 is a "-" sign

      SC=2 BC=2 PC=4
      Thanks for the info Mohit.
      Let me know if i am right !! :D

      Delete
  19. Thank You for the Helpful information in simple way

    ReplyDelete
  20. The following flowchart has been tested with two test cases.
    TC1: followed the path V X Z
    TC2: followed the path VWZ
    What level of coverage has been achieved?

    o a) Statement coverage 100%; Decision coverage 100%
    o b) Statement coverage 80%; Decision coverage 75%
    o c) Statement coverage 75%; Decision coverage 75%
    o d) Statement coverage 66%; Decision coverage 50%

    ReplyDelete
  21. Could not figure out how to calculate SC, BC, and PC after reading a bunch of materials. But this article helped to understand the process of calculation in the matter of minutes. Thanks a lot Mohit!

    ReplyDelete
  22. Very helpful for the students indeed.

    Regards,
    creately

    ReplyDelete
  23. Very Helpful, thank you for posting this example. It was really easy to understand.

    ReplyDelete
  24. Thank you Mohit,

    I had difficulty understanding this Pseudo codes and they've given Me problems not knowing how to start my flow chart, is there somewhere I can find more problems to practice on? please send Me feedback on the my mail below:

    dikoleisaac@live.com or dikoleisaac@gmail.com

    ReplyDelete
  25. Thank You Mohit.
    Your explanation was great. i am preparing for istqb and i could not identify how to calculate statement and branch coverage.. it was very helpful plus in a simple and easy way.

    ReplyDelete
  26. Your explanation was great.

    ReplyDelete
  27. Awesome simply Awesome

    ReplyDelete
  28. Thank you so much. It was very helpful.

    ReplyDelete
  29. Thank you . Very helpful.

    ReplyDelete
  30. //assume n1, n2, n3, count, sum and total are defined.
    public void someMethod(int n1, int num1, int num2, int num3) {

    for(int i=0; i< n1; i++) {
    if((n1 != num1)&&(n1 != num2)&&(n1 != num3))
    count = 1;
    else
    count = 2;

    if((n2 != num1)&&(n2 != num2)&&(n2 != num3))
    sum = 3;
    else
    sum = 4;

    if((n3 != num1)&&(n3 != num2)&&(n3 != num3))
    total = 5;
    else
    total = 6;
    }//end for(..)
    }//end of method
    Examine the sample code below then answer the following questions. How many tests are required for:
    a. Statement coverage
    b. Branch coverage.
    c. Traversing every path through the algorithm.
    i'm finding it's solution i'm new at this platform and i'm confused how to solve this it was the question in the paper

    ReplyDelete

Get Microsoft Office/ Excel Name Function in Java

Retrieve Microsoft Excel Name and Office Path In JAVA I have implemented an office name parsing function to reterieve which Office is in...

Get Counted