Unit tests that actually verify
Pure logic without mounting components, and the code that makes mocks pointless
A suite can have eighty-eight tests and a mutation score of 19%: the problem is almost never in the mocking, it is in the code that forces you to mock. The series starts from what you can test without mounting anything, shows where mocks turn into a patch, and gets to the refactoring that makes them unnecessary.
Eighty-eight tests, and a mutation score of 19%
The instinctive reaction in front of a suite that finds nothing is to blame the mocks: we mock too much, we mock badly, the tests verify the mocks instead of the code. Almost always that is the wrong diagnosis.
The problem is usually not in the mocking: it is in the code that forces you to mock. A Kafka connection opened at module level, a MongoDB client created on import, a singleton that initialises itself: every one of those lines makes it impossible to instantiate the logic without dragging half the system along, and the mocks become the patch.
The series starts from the other end: how much can be verified without mounting anything. Seventy-two tests on stores, composables and helpers, and not one component mounted. Then it shows where mocks are hiding a design problem. And it ends with the refactoring that makes them unnecessary: application factory, injected dependencies, and no sys.modules to tamper with.
What you will learn
- ✓ Test pure logic without mounting a single component
- ✓ Recognize when a mock is hiding a design problem
- ✓ Make a service testable with an application factory and dependency injection
Articles in the series
- 01Unit testing in Nuxt 3: 72 tests without mounting a single component 9 min
72 unit tests in Nuxt 3 covering only pure logic: Pinia stores, composables, API helpers. Zero added dependencies, zero mounted components.
→ - 02Your Flask service is untestable (and mocks aren't the problem) 14 min
88 tests, three Flask services, mutation score at 19%. The problem isn't the mocking: it's code that opens Kafka and MongoDB connections at import time.
→ - 03Testable Flask microservices: application factory, DI, and zero sys.modules hacks 9 min
Three Flask services with module-level Kafka and MongoDB connections, refactored to application factory with dependency injection. From 228 lines of conftest to 148.
→