0

I am working on an assignment that is asking me to not find a fault with 100% branch coverage and can make a test suite that achieves less than 100% branch coverage but DOES reveal the fault.

I really don't understand how this could be possible other than having a third input that has absolutely nothing to do with how the branching in the program works and only if that input is messed with could the branches not hit every branch yet still show it.

Like maybe

public int problemMethod(int a, int b, int c) 
{
  if(a > b)
  {
    return (a/c);
  }
  else
  {
    return 1;
  }
}

Like in this case I could go down every branch and get 100% branch coverage and not find the fault if c is never 0. But I could just do 1 test case where a IS > b and c IS 0. That would mean that I found the error but I never did the else branch. Meaning 50% branch testing but found the fault.

Right? I am just really confused on the wording of this problem.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
James
  • 11
  • 4
  • What is your question? It seems to me you understand the problem: 100% branch coverage with badly chosen values (or only happy path values) doesn't necessarily expose problems, while a single well-chosen test case which only produces 50% branch coverage can expose a problem. Similarly, 100% branch coverage which exposes the division by zero might not expose that instead of `a/c`, the code should have done `b/c` (or vice versa) – Mark Rotteveel Mar 01 '21 at 18:21
  • 1
    The rationale behind this assignment is probably to make you aware that 100% branch coverage doesn’t mean that there are no bugs present, and that it might not be a good metric to assure Software quality. It’s a lesson that in my experience has rarely been taught to management. – Axel Mar 01 '21 at 18:32
  • Thank you both for your responses. Like I said I just wanted to be sure I was getting the wording right that I am not leading myself astray. I was fairly certain I grasped the concept but I wanted to be sure my example was ok in execution. – James Mar 01 '21 at 18:34
  • 1
    Does this answer your question? [Test case for 100% branch coverage with no fault?](https://stackoverflow.com/questions/33536168/test-case-for-100-branch-coverage-with-no-fault) – Mike B Mar 01 '21 at 19:14

0 Answers0