Testing Microservices

Test pyramid: Unit > Integration > E2E.

Unit Test
def test_calculate_total():
    order = Order(items=[{"price": 10}, {"price": 20}])
    assert order.calculate_total() == 30

Integration Testing

Test interactions between services.

Contract Testing
@pact.given("product exists")
@pact.upon_receiving("GET product")
@pact.will_respond_with(200, body={"id": 1})

Chaos Engineering

Test resilience by injecting failures.

Netflix Chaos Monkey

Randomly terminates instances to test resilience