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.
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.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test suite starts | Test runner initialized, login function loaded | - | PASS |
| 2 | Run test_black_box_valid: call login('user', 'pass123') | Function receives valid credentials | Assert login returns True | PASS |
| 3 | Run test_black_box_invalid: call login('user', 'wrongpass') | Function receives invalid password | Assert login returns False | PASS |
| 4 | Run test_white_box_edge: call login('', '') | Function receives empty strings as input | Assert login returns False | PASS |
| 5 | Test suite ends | All tests executed | All assertions passed | PASS |