-3
1. if A > B
2.   if A > C
3.     Add A to X
4.   End if
5. End if

According to my understanding 2 test cases are required to achieve 100 % of the statement above. My reasons are:

  1. One statement is at line number 3.
  2. Second statement will be at line number 2. Because line number 2 will work as a statement for line number 1.

That's why looks like for 100% statement coverage I need 2 test cases. But on Scribd I have read that only 1 test case is needed.

What is correct?

  • 2
    It would help if you expanded your thinking: why do you think the answer is 2? What does that mean? Have a look here: asking. You likely get down votes for no research. It seems like an homework question... – Ray Oei Jan 23 '18 at 12:43
  • (1) 100% test coverage is wrong goal in production (2) coverage depends on tests you have (3) If this is NOT your own homework (which we will NOT do for you), explain what it is. – Peter M. Jan 23 '18 at 14:31
  • It is unclear what you mean by "statement coverage equal to 2". Coverage is expressed in %. Usually the goal of all questions like yours is to invent test cases that in sum reach all statements. There's also branch coverage when you want to reach all logical branches in tests, i.e, simulate situations when if condition is satisfied and situations when if condition is not satisfied. – dzieciou Jan 25 '18 at 10:55
2

There is exactly one executable statement in the example, so if the question is not asking for branch coverage, one test case will give 100% coverage.

An if statement is a flow, or branching statement. It evaluates conditions and redirects the application flow according to whether or not the conditions are met.

An executable statement acts on the application and system in some way. So the if statements are deciding whether the executable statement is run.

The single test case for 100% executable statement coverage is to run with a value of A that is greater than both B and C. When the test completes, the new value of X should be X + A.

For branch coverage you would need more test cases:

  1. A < B (the value of C is irrelevant because if A < B, statement 2 above will never be reached) - X is unchanged.
  2. A > B and A < C - X is unchanged.
  3. A > B and A > C - this condition will cause the executable statement to run. X(new) = X(original) + A

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.