tags : General Programming, Design Patterns

FAQ

Snapshots vs Mock

  • Snapshot: If you are testing what your API is supposed to respond with, that’s called a snapshot and libraries like jest have it built in.
  • Mock: If you are testing how your code handles data that is coming from an external API, then that’s called a mock. We have a sub-folder called something like “/tests/mocks” and they’re just a sampling of different common API responses that my service is expected to handle. A unit test will grab a specific mock data file and process it according to the logic in my system, then the output is examined for accuracy.
    • Related terms: goldens

TDD

  • red, green, refactor
    • red: write a test that fails
    • green: make the test pass
    • refactor: refactor it into something u r proud of
  • These are usually unit tests

Lean TDD

  1. have fun
  2. use tracer bullet test initially
  3. test behavior not implementation
  4. developer source and test code together
  5. focus on valuable tests, write feature tests, test usp(s)
  6. write test when you need them, refactor when u need to