Introduction
Testing software can be slow and costly if done only at the end or only manually. The test automation pyramid helps organize tests to catch problems early and keep testing efficient.
Imagine building a car. First, you test each part like the engine or brakes separately. Then, you check how these parts work together, like the engine with the transmission. Finally, you take the whole car for a test drive to see if everything works smoothly.
┌───────────────┐
│ End-to-End │
│ Tests (few) │
└───────┬───────┘
│
┌───────┴───────┐
│ Integration │
│ Tests (some) │
└───────┬───────┘
│
┌───────┴───────┐
│ Unit Tests │
│ (many) │
└───────────────┘import unittest # Unit test example def add(a, b): return a + b class TestAddFunction(unittest.TestCase): def test_add_positive(self): self.assertEqual(add(2, 3), 5) # Integration test example class Database: def __init__(self): self.data = {} def save(self, key, value): self.data[key] = value def get(self, key): return self.data.get(key) class Service: def __init__(self, db): self.db = db def store_value(self, key, value): self.db.save(key, value) def retrieve_value(self, key): return self.db.get(key) class TestServiceIntegration(unittest.TestCase): def test_store_and_retrieve(self): db = Database() service = Service(db) service.store_value('x', 10) self.assertEqual(service.retrieve_value('x'), 10) if __name__ == '__main__': unittest.main()