Introduction
Imagine you want to make sure only the right people can enter a locked room. Authentication testing helps check if a system correctly identifies users before giving access.
Think of a nightclub with a bouncer checking IDs at the door. The bouncer lets in people with valid IDs and refuses those without. They also watch to make sure people don’t sneak in after leaving.
┌─────────────────────────────┐
│ User tries to login │
└──────────────┬──────────────┘
│
┌───────▼────────┐
│ Check credentials│
└───────┬────────┘
│
┌─────────┴─────────┐
│ │
┌────▼────┐ ┌────▼─────┐
│Valid ID │ │Invalid ID│
└────┬────┘ └────┬─────┘
│ │
┌────▼─────┐ ┌────▼─────┐
│Grant │ │Reject │
│Access │ │Access │
└──────────┘ └──────────┘import unittest class AuthSystem: def __init__(self): self.users = {'alice': 'password123', 'bob': 'secure!'} def authenticate(self, username, password): return self.users.get(username) == password class TestAuthentication(unittest.TestCase): def setUp(self): self.auth = AuthSystem() def test_valid_credentials(self): self.assertTrue(self.auth.authenticate('alice', 'password123')) def test_invalid_credentials(self): self.assertFalse(self.auth.authenticate('alice', 'wrongpass')) def test_unknown_user(self): self.assertFalse(self.auth.authenticate('charlie', 'nopass')) if __name__ == '__main__': unittest.main()