Published Dec 15, 2014

We're Testing Your Patience...

Allen and Joe dive deep into the world of unit testing, Singleton patterns, and test automation, offering practical strategies and tools to enhance code quality, maintainability, and test efficiency.
Episode Highlights
Coding Blocks logo

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