Logical Coverage Criteria

Most basic three
(1) Predicate Coverage (PC)
Each predicate should evaluate to both true and false.
(2) Clause Coverage (CC)
Each clause in predicate should evaluate to both true and false.
(3)    Combinatorial Coverage (CBC)
All combinations of clause values should be considered.

Let's use an example to illustrate the idea.
Suppose we have Java code segment:
if((x<y || flag ) && list.contains("red")) { //do something; }

We can abstract the predicate (x<y || flag ) && list.contains("red") to (a ∨ b) ∧ c.
So predicate: p= (a ∨ b) ∧ c, and clauses: a,b, and c.
(1) PC
Test suite={p=true,p=false}, we don't care about the values of a,b,c as long as p=true and p=false are satisfied.

(2) CC
In this case, a, b and c all have to evaluate to both true and false. The truth table is shown below.

 

    a         b         c

-----------------------------

    T

-----------------------------

    F

-----------------------------

               T        

-----------------------------

               F

-----------------------------

                          T

-----------------------------

                          F

-----------------------------

 

We do not care about the blank cells. So test suite={(T,T,T),(F,F,F)} can satisfy CC.

 

(3) CBC

 

All combinations must be tested. So there will eight test cases.

 

    a         b         c

-----------------------------

    T         T         T

-----------------------------

    T         T         F

-----------------------------

    T         F         T

-----------------------------

    T         F         F

-----------------------------

    F         T         T

-----------------------------

    F         T         F

-----------------------------

    F         F         T

-----------------------------

    F         F         F

-----------------------------

 

There are other more sophisticated coverage criteria to better test software.

 

Reference: Paul Ammann & Jeff Offutt "Introduction to software testing"

 

 

 

 

 

 

 

 

你可能感兴趣的:(Logical Coverage Criteria)