0
0
Testing Fundamentalstesting~10 mins

Condition coverage in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks a simple function with two conditions combined by AND. It verifies that each condition is tested both true and false at least once, ensuring condition coverage.

Test Code - unittest
Testing Fundamentals
def check_conditions(a, b):
    if a > 0 and b > 0:
        return True
    else:
        return False

import unittest

class TestConditionCoverage(unittest.TestCase):
    def test_condition_coverage(self):
        # Test case 1: a > 0 true, b > 0 true
        self.assertTrue(check_conditions(1, 1))
        # Test case 2: a > 0 false, b > 0 true
        self.assertFalse(check_conditions(0, 1))
        # Test case 3: a > 0 true, b > 0 false
        self.assertFalse(check_conditions(1, 0))

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized-PASS
2Calls check_conditions(1, 1)Function evaluates a > 0 (true) and b > 0 (true)AssertTrue passes because both conditions truePASS
3Calls check_conditions(0, 1)Function evaluates a > 0 (false) and b > 0 (true)AssertFalse passes because first condition falsePASS
4Calls check_conditions(1, 0)Function evaluates a > 0 (true) and b > 0 (false)AssertFalse passes because second condition falsePASS
5Test endsAll assertions passedAll conditions covered true and falsePASS
Failure Scenario
Failing Condition: Missing test case where a > 0 is false but b > 0 is true
Execution Trace Quiz - 3 Questions
Test your understanding
What does condition coverage ensure in this test?
AAll possible combinations of conditions are tested
BEach condition is tested both true and false at least once
COnly the final output is checked
DConditions are tested only when both are true
Key Result
Condition coverage requires testing each condition in a decision as true and false at least once, even if not all combinations are tested.