Talk

They are not unit tests: a survey of unit-testing anti-patterns

LanguageEnglish
Audience levelIntermediate
Elevator pitch

The entire industry approves of unit testing but almost no one can fully agree on how to do it correctly, or even on what unit tests are. I’ll show you how testing turns into hell in real enterprises with the most common anti-patterns and propose solutions for all of them

Abstract

Similar to TDD, unit tests are one of the most misunderstood concepts in software engineering. In this session, I will cover the most important fallacies about unit testing and the most common anti-patterns. I will also show you how modern infrastructure (pytest-fixture-classes, inline-snapshot, dirty-equals, import-linter, mutmut, and pytest-xdist) makes it possible to avoid most of them.

We will discuss that the real goal of tests is not always stability and how tests often make refactoring and restructuring your project easy, not hard. I will define my criteria for good tests and then for the rest of the session, we will be using it to analyze anti-patterns and explore modern solutions to them. You will see:

  1. How people make their “units” too small and how you can prevent it using import-linter
  2. How people make their “units” too big and what architectural patterns can you use to make them smaller
  3. How the real value of tests is in the quality of their assertions and how mutation testing can measure it for you
  4. How people end up with asserting too much, and how inline-snapshot and dirty-equals make this problem obsolete
  5. How people try to cover the volatile parts of their software, and how coveragepy already has tooling to prevent it
  6. How slow tests hurt you, and how to make your tests fast even if you tried it many times and failed
  7. How to build an architecture that makes writing tests hard, and how to make it easy using inline-snapshot, pytest-fixture-classes, and a few clever tricks
  8. How you can mock your way into making your tests useless and what you should mock

After this session, your tests will become your friend instead of slowing you down.

TagsBest Practice, Testing
Participant

Stanislav Zmiev

I’m an experienced platform engineer and architect with a passion for open source and developer tools. The author of Cadwyn – a sophisticated API Versioning framework based on FastAPI. A contributor to numerous projects such as CPython and tortoise-orm. Currently building the future of finance at Monite.