0
0
Testing Fundamentalstesting~10 mins

Black-box vs white-box testing in Testing Fundamentals - Test Execution Compared

Choose your learning style9 modes available
Test Overview

This test compares black-box and white-box testing approaches by verifying a simple login function works correctly without and with knowledge of the code.

Test Code - unittest
Testing Fundamentals
import unittest

# Simple login function to test

def login(username, password):
    # White-box knowledge: valid credentials are 'user' and 'pass123'
    if username == 'user' and password == 'pass123':
        return True
    else:
        return False

class TestLogin(unittest.TestCase):
    def test_black_box_valid(self):
        # Black-box test: only input/output knowledge
        self.assertTrue(login('user', 'pass123'))

    def test_black_box_invalid(self):
        self.assertFalse(login('user', 'wrongpass'))

    def test_white_box_edge(self):
        # White-box test: testing edge case knowing code
        self.assertFalse(login('', ''))

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test suite startsTest runner initialized, login function loaded-PASS
2Run test_black_box_valid: call login('user', 'pass123')Function receives valid credentialsAssert login returns TruePASS
3Run test_black_box_invalid: call login('user', 'wrongpass')Function receives invalid passwordAssert login returns FalsePASS
4Run test_white_box_edge: call login('', '')Function receives empty strings as inputAssert login returns FalsePASS
5Test suite endsAll tests executedAll assertions passedPASS
Failure Scenario
Failing Condition: login function incorrectly returns True for invalid credentials
Execution Trace Quiz - 3 Questions
Test your understanding
Which test uses only input and output knowledge without looking at the code?
AUnit testing
BWhite-box testing
CBlack-box testing
DIntegration testing
Key Result
Black-box testing focuses on inputs and outputs without code knowledge, while white-box testing uses internal code knowledge to design tests, especially for edge cases.