Condition coverage is seen for Boolean expression, condition coverage ensures whether all the Boolean expressions have been evaluated to both TRUE and FALSE.
Condition coverage is also known as Predicate Coverage
Condition coverage and predicate coverage are code coverage metrics used in software testing to assess the thoroughness of Test Cases. They both focus on measuring how well the tests exercise the code, but they have different goals and criteria.
Condition coverage, also known as decision coverage or branch coverage, aims to ensure that each possible branch or decision point in the code is executed at least once during testing.
It primarily focuses on the true and false outcomes of each decision point (if statements, loops, etc.).
The goal is to make sure that every branch is taken and both the “true” and “false” conditions are tested.
This metric is often expressed as a percentage, indicating the proportion of branches executed during testing.
Predicate coverage is a more fine-grained metric that goes beyond just examining branches and focuses on evaluating conditions (predicates) within those branches.
It ensures that all combinations of conditions within a decision are tested, including different conditions in complex logical expressions.
Predicate coverage aims to test the logical combinations of conditions to ensure that all paths within a decision are exercised.
Like condition coverage, predicate coverage is also expressed as a percentage, representing the proportion of unique condition combinations tested.
Let us take an example to explain Condition Coverage
IF (“X && Y”)
In order to suffice valid condition coverage for this pseudo-code following tests will be sufficient.
TEST 1: X=TRUE, Y=FALSE
TEST 2: X=FALSE, Y=TRUE
Note: 100% condition coverage does not guarantee 100% decision coverage.
In summary, condition coverage is concerned with ensuring that all possible branches are executed, while predicate coverage dives deeper to make sure all combinations of conditions within branches are tested. Predicate coverage is more thorough but more challenging in practice, especially in code with complex logical expressions. The choice between these coverage metrics depends on the testing objectives and the specific requirements of the software being tested.