4 ms·
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 test
by arp242 3y ago
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: "foo@example.com") # 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.