Dummy: Just a value Stub: Returns canned answers Fake: Simpler implementation Mock: Has interaction-verification baked in Spy: Can be asked questions about interactions later Martin Fowler: Mocks aren't Stubs @dtanzer 23
result matches the expected result Use dummies, stubs or fakes if you need them expect "Frontdoor testing" Interaction-Based Interaction-Based Interaction-Based Interaction-Based Interaction-Based Nothing to observe Verify expected interaction has happened Use mocks and/or spies; and dummies, stubs or fakes if you need them when / verify Backdoor testing @dtanzer 41
Boundary AND Hard to Test Boundary AND Hard to Test Boundary AND Hard to Test Electron IPC Electron IPC Electron IPC Electron IPC Electron IPC sendSync(channel: C_MAIN, ...args: any[]) { return ipcRenderer.sendSync(channel, ...args) } sendSync(window: BrowserWindow, channel: C_RENDERER, ...args: any[]) { window.webContents.send(channel, ...args) } @dtanzer 52
Error Boundary 4. Make Test-Doubles Visible 5. Fake DMZ / Outside World 6. Result- -or- Interaction-based 7. Don't Mock what You don't Own 8. Integration-Test at Boundary 9. Leverage the Type System @dtanzer 58
Do not mock what you don't own Avoid mocks to make untestable code testable Avoid mocks that return mocks Avoid expect and verify in the same test Don't mix result-based and interaction-based testing @dtanzer 59