Kos112567
Kos112567

Reputation: 87

Condition coverage vs Decision coverage testing

What is the difference between Condition coverage and Decision coverage?

I have a simple example:

IF (A && B) THEN

Condition coverage will have two tests (the result will be FALSE):

  1. A = TRUE, B = FALSE
  2. A = FALSE, B = TRUE

Decision coverage will have only one test (the result will be TRUE):

  1. A = TRUE, B = TRUE

Do I understand that right?

Upvotes: 7

Views: 12905

Answers (2)

Vitor Bona
Vitor Bona

Reputation: 39

In Condition Coverage (also know as Predicate Coverage) each of the boolean expressions must be evaluated to true and false at least once. For example:

IF ((A || B) && C) THEN

To satisfy the condition coverage criteria, you could use the following tests:

  1. A = true | B = not eval | C = false

  2. A = false | B = true | C = true

  3. A = false | B = false | C = not eval

In Decision Coverage (also know as Branch Coverage) you have to test all posible branches. For example:

IF (A){
   ...
ELSE IF(B) {
   ...
} ELSE {
   ...
}

To satisfy the decision coverage criteria for this piece of code you'll need to run 3 tests:

  1. A is evaluated to true

  2. A is evaluated to false and B is evaluated to true

  3. A and B are evaluated to false

Upvotes: 3

Pratik
Pratik

Reputation: 19

Example:

  1. a = int(input())
  2. if a=0:
  3. print("Zero")
    
  4. elif a>0:
  5. print("Positive")
    
  6. else:
  7. print("Negative")
    

Here the Statement no. 2, 4 and 6 will be considered under Condition Coverage. (Bcz here you are checking the condition that is it equal to 0 or not, is it greater than 0 or not, etc.)

and the statement no. 3, 5 and 7 will be considered under Decision coverage. (Bcz these are the decision taken after cheking the condition)

Imp Note: Decision Coverage and Branch Coverage are different.

Upvotes: 1

Related Questions