Mocking Can Lead To False Positive Tests 🔊
fagnerbrack.com
5 min read
View original
Summary (TL;DR)
Mocking with primitive values can cause false positives in tests. If the function reassigns the input variable to the same value used in the test, the test still passes even though it's testing the wrong behavior. Solutions include passing object references instead of primitives, using generative testing, or triangulation with multiple test values. Design choices to avoid mocks altogether can also help.