News for hackers. Stuff that matters.
Re:Don't Use Mocks by arp242 on Wednesday June 21, 2023 @04:31AM (#36415933)
How I understand it:

A mock is a set of fixed data; sometimes people even load these from YAML documents and the like. They're often re-used for different tests.

A fake is a "fake" object created when needed, with the parameters you need.

Mock:

  user = load_user_mock()
  article = load_article_mock()
  run_test(user, article)
Fake:

  user = newUser(Name: "foo", Email: "[email protected]")  # Or generate random data
  article = newArticle(User: user, Title: "bar")
  run_test(user, article)
The difference is somewhat subtle, but I often find mocks very inconvenient because you can't "just" change one without lots of stuff falling over. It's also much harder to do something "special" with them for that one test.

There are no comments on this comment yet.