Stop Using Mocks In Unit Tests

Опубликовано: 24 Апрель 2026
на канале: Kiki's Bytes
3,788
108

Preface: most of the information in this video are lessons I learned from Unit Testing Principles, Practices, and Patterns by Vladimir Khorikov.

I'm a big advocate of avoiding mocks in your unit tests, in particular your domain logic code. I always felt that using mocks made my code more fragile and doesn't bring issues to the surface until it happens on production. For the longest time, I still used mocks at work because that's what everyone else was doing.

After reading Unit Testing Principles, Practices, and Patterns a couple years back, it reassured me that I was not crazy.

I hope that you give this book a read. It has stuck with me whenever I write code.

Thank you for your time.

Timestamps:
00:00:00 - Intro
00:00:34 - What is a good unit test?
00:00:57 - False positives
00:02:13 - Deeply nested dependencies
00:02:49 - Code with api/database calls
00:03:26 - Code that glues everything together
00:04:29 - Final thoughts

Music:
With Some Malice - Francesco D'Andrea :    • With Some Malice - Francesco D'Andrea | Ci...  
Chillpeach - Gameplay :    • [no copyright music] 'Gameplay' cute backg...