0
0
Testing Fundamentalstesting~10 mins

Why white-box testing examines code internals in Testing Fundamentals - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test simulates a white-box testing scenario where the tester checks the internal logic of a simple function. It verifies that the function behaves correctly for given inputs by examining its code paths.

Test Code - unittest
Testing Fundamentals
import unittest

# Function to test: returns True if number is even, else False
def is_even(num):
    if num % 2 == 0:
        return True
    else:
        return False

class TestIsEven(unittest.TestCase):
    def test_even_number(self):
        self.assertTrue(is_even(4))

    def test_odd_number(self):
        self.assertFalse(is_even(5))

if __name__ == '__main__':
    unittest.main()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, test cases loaded-PASS
2Calls is_even(4)Function executes with input 4Checks if 4 % 2 == 0, returns TruePASS
3Asserts that is_even(4) returns TrueAssertion compares returned value True with expected TrueassertTrue passesPASS
4Calls is_even(5)Function executes with input 5Checks if 5 % 2 == 0, returns FalsePASS
5Asserts that is_even(5) returns FalseAssertion compares returned value False with expected FalseassertFalse passesPASS
6Test endsAll test cases executed successfully-PASS
Failure Scenario
Failing Condition: Function returns incorrect result for input (e.g., is_even(4) returns False)
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check inside the is_even function?
AIf the number is divisible by 2 without remainder
BIf the number is greater than 2
CIf the number is positive
DIf the number is less than 10
Key Result
White-box testing examines the internal code logic to ensure each decision path works correctly, which helps catch errors that black-box testing might miss.