Search code examples
c#if-statementwhite-boxwhite-box-testing

Does statement coverage count false if statements?


When checking statement coverage for my code:

 double programme(double x, double y)
 {
    double z 
    if(x>=5){
      z = 15;
    }
    else if(x>=3){
      z= 10;
    }
    else {
      z=0;
    }
    if (y>z)
    {
      z=y;
    }

    return z;
}

using two test cases (eg test 1: x = 6, y = 10 and test 2: = 3, y =5)

I'm not sure if the statement coverage is equal to 100% or 66% based on the fact that I'm not sure if you count the last if statement as it is false both times.


Solution

  • There are eight statements in your method - three conditionals, four assignments, and a return:

    1. if (x>=5)
    2. z=15
    3. if (x>=3)
    4. z=10
    5. z=0
    6. if (y>z)
    7. z=y
    8. return

    The first test case covers statements 1, 2, 6, and 8. The second test case covers 1, 3, 4, 6, and 8. Therefore, statements 1, 2, 3, 4, 6, and 8 are covered, for 6 out of 8 or 75% coverage.