Files
junhong_cmp_fiber/.agents/skills/tdd/interface-design.md
break cf36f1447f
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m24s
尝试某个skills
2026-06-16 18:58:55 +09:00

653 B

Interface Design for Testability

Good interfaces make testing natural:

  1. Accept dependencies, don't create them

    // Testable
    function processOrder(order, paymentGateway) {}
    
    // Hard to test
    function processOrder(order) {
      const gateway = new StripeGateway();
    }
    
  2. Return results, don't produce side effects

    // Testable
    function calculateDiscount(cart): Discount {}
    
    // Hard to test
    function applyDiscount(cart): void {
      cart.total -= discount;
    }
    
  3. Small surface area

    • Fewer methods = fewer tests needed
    • Fewer params = simpler test setup