Bird
Raised Fist0
Testing Fundamentalstesting~6 mins

Condition coverage in Testing Fundamentals - Full Explanation

Choose your learning style10 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 coverage → Testing each condition in a decision for both true and false outcomes.
Decision coverage → Testing the overall decision outcome for true and false at least once.
Condition → A single boolean expression inside a decision.
Limitations → Condition 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.

Practice

(1/5)
1. What does condition coverage ensure in software testing?
easy
A. All possible input values are tested
B. Only the overall decision outcome is tested once
C. Each part of a decision is tested for both true and false outcomes
D. Only syntax errors are detected

Solution

  1. Step 1: Understand condition coverage definition

    Condition coverage requires testing each atomic condition in a decision for both true and false values.
  2. Step 2: Compare options with definition

    Each part of a decision is tested for both true and false outcomes matches this definition exactly, while others describe different testing scopes.
  3. Final Answer:

    Each part of a decision is tested for both true and false outcomes -> Option C
  4. Quick Check:

    Condition coverage = test each condition true/false [OK]
Hint: Test each condition true and false separately [OK]
Common Mistakes:
  • Confusing condition coverage with decision coverage
  • Thinking only overall decision outcome matters
  • Assuming all inputs must be tested
2. Which of the following is the correct syntax to represent a condition in a test case for condition coverage?
easy
A. if a and b then ...
B. if a && b { ... }
C. if (a & b) { ... }
D. if (a && b) { ... }

Solution

  1. Step 1: Identify correct syntax for logical AND in common languages

    In languages like JavaScript, Java, and C, logical AND is written as && inside parentheses.
  2. Step 2: Evaluate each option

    if (a && b) { ... } uses correct syntax with parentheses and &&. if a and b then ... uses incorrect syntax (no parentheses, wrong keywords). if (a & b) { ... } uses bitwise AND &, not logical AND. if a && b { ... } misses parentheses.
  3. Final Answer:

    if (a && b) { ... } -> Option D
  4. Quick Check:

    Logical AND syntax = && with parentheses [OK]
Hint: Use parentheses and && for logical AND [OK]
Common Mistakes:
  • Using single & instead of && for logical AND
  • Omitting parentheses around conditions
  • Using incorrect keywords like 'then'
3. Consider the decision: if (x > 0 && y == 5). Which test inputs achieve full condition coverage?
medium
A. x=1, y=5 and x=-1, y=4
B. x=1, y=5 and x=1, y=4
C. x=0, y=5 and x=1, y=5
D. x=1, y=5 and x=-1, y=5

Solution

  1. Step 1: Identify conditions and their true/false values

    Conditions: (x > 0) and (y == 5). To cover both true and false for each, we need inputs where x > 0 is true and false, and y == 5 is true and false.
  2. Step 2: Check each option for condition coverage

    x=1, y=5 and x=-1, y=4: x=1,y=5 (x>0 true, y==5 true), x=-1,y=4 (x>0 false, y==5 false) covers all true/false for both conditions. Others miss some false cases.
  3. Final Answer:

    x=1, y=5 and x=-1, y=4 -> Option A
  4. Quick Check:

    Test each condition true and false separately [OK]
Hint: Test each condition true and false independently [OK]
Common Mistakes:
  • Testing only overall decision true/false
  • Missing false case for one condition
  • Assuming one test covers all conditions
4. Given the code snippet:
if (a || b) {
  // do something
}

Which test set achieves condition coverage?
medium
A. a=true, b=false and a=false, b=true
B. a=true, b=false and a=false, b=false
C. a=true, b=true only
D. a=false, b=false only

Solution

  1. Step 1: Understand condition coverage for OR operator

    For a || b, condition coverage requires testing a and b each as true and false separately.
  2. Step 2: Evaluate test sets

    a=true, b=false and a=false, b=true tests a=true,b=false (a true, b false) and a=false,b=true (a false, b true), covering both true and false for each condition. Others miss some cases.
  3. Final Answer:

    a=true, b=false and a=false, b=true -> Option A
  4. Quick Check:

    Test each condition true and false separately [OK]
Hint: Test each condition true and false separately for OR [OK]
Common Mistakes:
  • Confusing with decision coverage
  • Assuming one test covers both conditions
  • Ignoring condition coverage for OR
5. You have the decision: if ((p && q) || r). Which minimal test set achieves full condition coverage?
hard
A. p=true, q=true, r=false; p=false, q=true, r=false; p=false, q=false, r=false
B. p=true, q=false, r=false; p=false, q=true, r=false; p=false, q=false, r=true
C. p=true, q=true, r=false; p=false, q=false, r=false
D. p=true, q=false, r=true; p=false, q=false, r=false

Solution

  1. Step 1: Identify atomic conditions and their true/false needs

    Conditions: p, q, r. Condition coverage requires each to be true and false at least once.
  2. Step 2: Check each test set for coverage

    p=true, q=false, r=false; p=false, q=true, r=false; p=false, q=false, r=true tests p=true,q=false,r=false (p true, q false, r false), p=false,q=true,r=false (p false, q true, r false), and p=false,q=false,r=true (p false, q false, r true). This covers true and false for all conditions minimally.
  3. Final Answer:

    p=true, q=false, r=false; p=false, q=true, r=false; p=false, q=false, r=true -> Option B
  4. Quick Check:

    Each condition true and false tested once [OK]
Hint: Test each condition true and false once in minimal sets [OK]
Common Mistakes:
  • Missing false case for one condition
  • Testing only overall decision outcomes
  • Using redundant tests beyond minimal coverage
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard