blob: 73d0a3013d7a911521bd1600e629c5c253f83c59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
|