Some strange stories about
mocks
And why we don’t like them?
Andrew
Nashkolniy
Matic Insurance
Story #1: The Prehistory
Story #2: Testing with mocks
With Mocks Pros:
- Isolation.
With Mocks Pros:
- Isolation.
- Speed.
With Mocks Pros:
- Isolation.
- Speed.
- Accuracy.
With Mocks Cons:
- Avoided Contracts.
With Mocks Cons:
- Avoided Contracts.
- Rely on Integrations.
With Mocks Cons:
- Avoided Contracts.
- Rely on Integrations.
- Hard Refactoring.
Story #3: Testing without mocks
Without Mocks Pros:
- Refactoring.
Without Mocks Pros:
- Refactoring.
- Reliability.
Without Mocks Cons:
- Longer runtime.
Without Mocks Cons:
- Longer runtime.
- Snowball effect.
Without Mocks Cons:
- Longer runtime.
- Snowball effect.
- You still use mocks.
Story #4: Origins
Problems with mocks in Java:
- Other classes side effects.
Problems with mocks in Ruby:
- Weak input params checks.
- No output params checks.
- Other classes side effects.
Interfaces
&
Strong typing
Unacceptable problems:
- Refactoring difficulties.
Unacceptable problems:
- Refactoring difficulties.
- Unreliable tests.
No mocks by default. But...
Good usage mocks:
- Networking.
- Streams.
- IO operations.
- Time.
- System calls.
In the very end it really depends
Materials:
- https://www.youtube.com/watch?v=KYG5C1CEkOk
- https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70
c90a6a
- https://blog.codecentric.de/en/2018/03/mock-what-when-how
- https://blog.carbonfive.com/2011/02/11/better-mocking-in-ruby
- https://www.solutionsiq.com/resource/blog-post/to-mock-or-not-to-mock-is-that-even-a-question
- https://clean-swift.com/to-mock-or-not-to-mock
- https://blog.codecentric.de/en/2017/07/mocks-real-thing-tips-better-unit-testing
- https://dev.to/asizikov/you-are-mocking-it-wrong-5gh3
- https://www.swiftbysundell.com/posts/mock-free-unit-tests-in-swift
- https://semaphoreci.com/community/tutorials/mocking-with-rspec-doubles-and-expectations
- https://tomassetti.me/mocking-in-java-why-mocking-why-not-mocking-mocking-also-those-awful-private-static-methods
- https://softwareengineering.stackexchange.com/questions/363112/is-it-really-a-bad-practice-to-mock-a-pojo-value-object-if-you-dont-care-ab
ou
- https://stackoverflow.com/questions/6875173/to-mock-or-not-to-mock
- ...
Thank you!

Some strange stories about mocks.