0
0
Testing Fundamentalstesting~6 mins

Condition coverage in Testing Fundamentals - Full Explanation

Choose your learning style9 modes available
Introduction
When testing software, it is important to check that every part of the code works correctly. One challenge is to make sure that all the different conditions in decisions are tested, so no hidden errors remain.
Explanation
What is Condition Coverage
Condition coverage means testing each individual condition in a decision to see if it can be true and false. This helps find errors that happen only when certain conditions change. It looks at each condition separately, not just the whole decision.
Condition coverage ensures every condition in a decision is tested for both true and false outcomes.
Difference from Decision Coverage
Decision coverage tests whether the whole decision (like an if statement) is true or false at least once. Condition coverage goes deeper by testing each part of the decision separately. This means condition coverage is more detailed and can catch more errors.
Condition coverage tests each condition inside a decision, unlike decision coverage which tests the decision as a whole.
How Condition Coverage Works
For each condition in a decision, tests are created to make the condition true and false. This means if a decision has two conditions, at least two tests are needed to cover both possibilities for each condition. This helps ensure all logical paths are checked.
Tests must make each condition true and false to achieve condition coverage.
Limitations of Condition Coverage
Condition coverage does not guarantee that all combinations of conditions are tested together. Some errors happen only when multiple conditions interact. For that, stronger coverage like multiple condition coverage is needed.
Condition coverage alone may miss errors caused by combinations of conditions.
Real World Analogy

Imagine a security system with multiple sensors, like a door sensor and a window sensor. Condition coverage is like testing each sensor separately to make sure it triggers correctly when opened or closed.

What is Condition Coverage → Testing each sensor individually to see if it detects open and closed states
Difference from Decision Coverage → Checking if the whole security system triggers versus checking each sensor separately
How Condition Coverage Works → Creating tests that open and close each sensor to verify they work
Limitations of Condition Coverage → Not testing what happens if both door and window sensors open at the same time
Diagram
Diagram
┌───────────────────────────────┐
│         Decision (if)          │
│ ┌───────────────┐ ┌───────────┐ │
│ │ Condition A   │ │ Condition B│ │
│ └──────┬────────┘ └─────┬─────┘ │
│        │                │       │
│   True / False      True / False│
└────────┴────────────────┴───────┘
Diagram showing a decision with two conditions, each tested for true and false values.
Key Facts
Condition coverageTesting each condition in a decision for both true and false outcomes.
Decision coverageTesting the overall decision outcome for true and false at least once.
ConditionA single boolean expression inside a decision.
LimitationsCondition coverage does not test all combinations of multiple conditions.
Code Example
Testing Fundamentals
def check_access(age, has_ticket):
    if age >= 18 and has_ticket:
        return "Access granted"
    else:
        return "Access denied"

# Tests for condition coverage
print(check_access(20, True))   # Both conditions true
print(check_access(16, True))   # age false, has_ticket true
print(check_access(20, False))  # age true, has_ticket false
print(check_access(16, False))  # Both conditions false
OutputSuccess
Common Confusions
Condition coverage means testing all possible combinations of conditions.
Condition coverage means testing all possible combinations of conditions. Condition coverage tests each condition separately for true and false, but does not cover all combinations; that requires multiple condition coverage.
Decision coverage and condition coverage are the same.
Decision coverage and condition coverage are the same. Decision coverage tests the whole decision outcome, while condition coverage tests each individual condition inside the decision.
Summary
Condition coverage tests each condition in a decision for both true and false outcomes to find hidden errors.
It is more detailed than decision coverage but does not test all combinations of conditions.
Proper tests must make each condition true and false to achieve condition coverage.