Don't Mock What You Don't Own: A Better Way to Test Third-Party Dependencies

2025-06-18
Don't Mock What You Don't Own: A Better Way to Test Third-Party Dependencies

This article tackles a common problem in unit testing: handling third-party dependencies. Using a Docker repository client as an example, the author demonstrates the drawbacks of directly mocking third-party dependencies (like HTTP clients): tests become complex, brittle, and hard to understand. The proposed solution involves introducing a thin abstraction layer to decouple business logic from external dependencies, simplifying testing and improving code readability and maintainability. This approach not only leads to cleaner and more concise tests but also enhances the readability and maintainability of the business logic itself. While acknowledging exceptions, the author concludes that this principle helps write more elegant and maintainable tests in most cases.

Read more

Design Pressure: The Invisible Hand Shaping Your Code

2025-05-25
Design Pressure: The Invisible Hand Shaping Your Code

Ever feel that gut feeling something's wrong in your code but can't pinpoint it? Hynek Schlawack's PyCon US 2025 talk explores 'design pressure,' the invisible force shaping your architecture. He delves into topics like coupling types, attractive nuisances in software design, and type-driven design, highlighting trade-offs in data mapping and typestate patterns. The talk also critically examines the impact of ORMs and async primitives on code complexity.

Read more
Development code architecture