Bird
Raised Fist0
Testing Fundamentalstesting~20 mins

Condition coverage in Testing Fundamentals - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Condition Coverage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Condition Coverage

Which statement best describes condition coverage in software testing?

AIt requires each individual condition in a decision to be evaluated to both true and false at least once.
BIt tests only the overall decision outcome without checking individual conditions.
CIt ensures every possible combination of conditions in a decision is tested.
DIt focuses on testing the program's performance under different load conditions.
Attempts:
2 left
💡 Hint

Think about testing each part of a decision separately.

❓ Predict Output
intermediate
2:00remaining
Condition Coverage Test Outcome

Consider the following code snippet:

def check_values(a, b):
    if a > 0 and b > 0:
        return "Both positive"
    else:
        return "Not both positive"

If tests run with inputs (1, 1) and (1, -1), what is the condition coverage achieved?

ANeither condition evaluated false.
BBoth conditions (a > 0 and b > 0) evaluated true and false at least once each.
COnly the overall decision evaluated true and false; individual conditions not fully tested.
DOnly the second condition (b > 0) evaluated true and false; first condition (a > 0) only true.
Attempts:
2 left
💡 Hint

Check the values of a and b in each test case.

❓ assertion
advanced
2:00remaining
Writing Assertions for Condition Coverage

Given the function below, which assertion set best helps achieve condition coverage for the decision?

def is_eligible(age, income):
    if age >= 18 and income > 20000:
        return True
    else:
        return False
Aassert is_eligible(20, 25000) == True and assert is_eligible(17, 25000) == False
Bassert is_eligible(17, 25000) == False and assert is_eligible(20, 25000) == True
Cassert is_eligible(20, 25000) == True and assert is_eligible(17, 15000) == False
Dassert is_eligible(20, 15000) == False and assert is_eligible(17, 15000) == False
Attempts:
2 left
💡 Hint

Each condition must be true and false at least once.

🔧 Debug
advanced
2:00remaining
Debugging Condition Coverage in Test Cases

Test cases for the function below achieve full condition coverage. Which statement best describes the coverage?

def check_access(user_role, is_active):
    if user_role == "admin" or is_active:
        return "Access granted"
    else:
        return "Access denied"

# Test cases:
# 1. ("admin", True)
# 2. ("user", True)
# 3. ("admin", False)
AThe test cases never evaluate user_role as "user" when is_active is false.
BThe test cases never evaluate is_active as false when user_role is not admin.
CThe test cases do not test user_role as "admin" with is_active true.
DThe test cases cover all conditions fully.
Attempts:
2 left
💡 Hint

Check if each condition is true and false at least once.

❓ framework
expert
2:00remaining
Implementing Condition Coverage in Automated Tests

Which test framework feature best supports measuring condition coverage automatically during test runs?

ACondition coverage analyzer that tracks each boolean condition's true and false evaluations.
BMutation testing tool that modifies code to check test effectiveness.
CCode coverage tool that tracks which lines of code are executed.
DPerformance profiler that measures execution time of tests.
Attempts:
2 left
💡 Hint

Focus on tools that measure condition evaluation, not just line execution.

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