diff options
author | Jasper Ras <jras@hostnet.nl> | 2025-05-17 09:03:45 +0200 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2025-05-17 09:03:45 +0200 |
commit | d4bd3ad4a869c87fcfa4f83b42555a6c8e1bc746 (patch) | |
tree | 74cbfcd6ff623e272be389dd7d40d8e45d1f96d5 /Mocks aren't stubs.md | |
parent | 78211f96953bc1a63570f2430cee4ad92c841ce4 (diff) |
vault backup: 2025-05-17 09:03:45
Diffstat (limited to 'Mocks aren't stubs.md')
-rw-r--r-- | Mocks aren't stubs.md | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Mocks aren't stubs.md b/Mocks aren't stubs.md new file mode 100644 index 0000000..73d0a30 --- /dev/null +++ b/Mocks aren't stubs.md @@ -0,0 +1,27 @@ +--- +tags: + - testing + - dev +--- +A "test double" is any kind of object that pretends to be a real object. + +- Dummy: just satisfies the interface without actually doing anything. Just there to wire things up. +- Fake: Implement the interface but in a simple way; e.g in memory db. +- Stubs: similar to a fake but returns answers specifically for the test. +- Spies: a stub that keeps a record of how they were called. +- Mocks: objects pre-programmed with expectations of how they are to be used which is verified at the end of the test. + +A "Mock Object" mimics real objects for testing. They encourage testing based on behavior verification, because we can tell what functions we expect to be called on it and what they will return. +This is what I did a lot in PHP with phpunit & prophecy. + +Mock object verifies behavior, did we make the expected calls etc. While if a much simpler stub is used we only verify its state. + +--- + +Dichotomy between classical and mockist TDD styles. + +- Classical: prefers real object, and grabs double when necessary. +- Mockist: uses mocks always. + +Classical a.k.a detroit style +Mockist a.k.a london style |