0
0
Testing Fundamentalstesting~10 mins

Data validation rules in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the data entered into a form meets the required validation rules. It verifies that invalid data is rejected and valid data is accepted.

Test Code - PyTest
Testing Fundamentals
def validate_age(age):
    if not isinstance(age, int):
        return False
    if age < 0 or age > 120:
        return False
    return True


def test_validate_age():
    assert validate_age(25) == True
    assert validate_age(-1) == False
    assert validate_age(130) == False
    assert validate_age('twenty') == False
    assert validate_age(0) == True
    assert validate_age(120) == True

if __name__ == '__main__':
    test_validate_age()
Execution Trace - 14 Steps
StepActionSystem StateAssertionResult
1Test startsTest environment ready, validate_age function loaded-PASS
2Call validate_age(25)Function receives integer 25Check if 25 is valid age (0 <= 25 <= 120)PASS
3Assert validate_age(25) == TrueFunction returned TrueAge 25 is validPASS
4Call validate_age(-1)Function receives integer -1Check if -1 is valid age (0 <= -1 <= 120)PASS
5Assert validate_age(-1) == FalseFunction returned FalseAge -1 is invalidPASS
6Call validate_age(130)Function receives integer 130Check if 130 is valid age (0 <= 130 <= 120)PASS
7Assert validate_age(130) == FalseFunction returned FalseAge 130 is invalidPASS
8Call validate_age('twenty')Function receives string 'twenty'Check if input is integerPASS
9Assert validate_age('twenty') == FalseFunction returned FalseNon-integer input is invalidPASS
10Call validate_age(0)Function receives integer 0Check if 0 is valid age (0 <= 0 <= 120)PASS
11Assert validate_age(0) == TrueFunction returned TrueAge 0 is validPASS
12Call validate_age(120)Function receives integer 120Check if 120 is valid age (0 <= 120 <= 120)PASS
13Assert validate_age(120) == TrueFunction returned TrueAge 120 is validPASS
14Test endsAll assertions passed-PASS
Failure Scenario
Failing Condition: Function returns True for invalid age like -1 or string input
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check when calling validate_age(-1)?
AThat the function accepts strings
BThat negative ages are valid
CThat negative ages are invalid
DThat age 0 is invalid
Key Result
Always test boundary values and invalid data types to ensure data validation rules work correctly.