We're Testing Your Patience...

Topics covered
Popular Clips
Episode Highlights
Implementation
Implementing Singleton patterns can be fraught with challenges, particularly when dealing with dependencies like databases or file systems. Joe Zack highlights that if a static constructor-based singleton fails, it will never reinstantiate, causing persistent issues. He suggests using an instance property version to reset values during testing, ensuring each test starts with a fresh state 1. This approach helps avoid dependencies between tests, which is crucial for accurate unit testing.
If you actually have a test that depends on the outcome of another test, you're doing it wrong.
--- Joe Zack
Ensuring tests can run out of order without failing is a key indicator of proper implementation, as it proves the absence of hidden dependencies 1.
Dependencies
Managing dependencies within Singleton patterns is essential for enhancing testability. Joe Zack and Alan Underwood discuss how singletons often hide dependencies, making unit testing difficult. Joe suggests that using dependency injection can mitigate these issues by allowing dependencies to be passed in rather than created within the singleton 2. This approach can improve the testability of singletons, although it is not a common practice.
Singletons often hide dependencies, but that's not a requirement of the singleton; it's just how everyone uses them.
--- Joe Zack
Alan notes that while singletons are often used poorly, proper implementation and loose coupling can alleviate many of these challenges 2.
Related Episodes


Is Kubernetes Programming?
Answers 383 questions

Clean Code - How to Write Classes the Right Way
Answers 383 questions

Clean Architecture - Are Microservices Truly Decoupled?
Answers 383 questions

The DevOps Handbook – The Value of A/B Testing
Answers 383 questions

Minimum Viable Continuous Delivery
Answers 383 questionsDesign Patterns Part 3
Answers 383 questions

Google's Engineering Practices - What to Look for in a Code Review
Answers 383 questions

Keyboards, Cloud Costs, Static Analysis, and Philosophy
Answers 383 questionsClean Code - How to Write Amazing Functions
Answers 383 questionsSilverlighting through your College Enumeration
Answers 383 questions

Software Design Anti-patterns
Answers 383 questionsDesign Patterns Part 1
Answers 383 questions

Why Domain Driven Design
Answers 383 questionsCommand, Repository and Mediator Design Patterns
Answers 383 questionsHow to be an Intermediate Programmer
Answers 383 questions
