mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 08:46:22 +02:00
586 B
586 B
Interface Design for Testability
Good interfaces make testing natural:
- Accept dependencies, don't create them
# Testable
def process_order(order, payment_gateway):
pass
# Hard to test
def process_order(order):
gateway = StripeGateway()
- Return results, don't produce side effects
# Testable
def calculate_discount(cart) -> float:
return discount
# Hard to test
def apply_discount(cart) -> None:
cart.total -= discount
- Small surface area
- Fewer methods = fewer tests needed
- Fewer params = simpler test setup