Testing the Class Purpose
We have separated the testing of the singleton nature from the testing of the class’s functional purpose and addressed how to test the singleton nature. Testing the functional purpose is easy, right? It would be, except for one thing: we cannot construct an instance except through the singleton mechanism. The difficulty in testing the singleton’s purpose is that we have no way to test it with a Fresh Fixture. The more tests we write, the higher the chances we will create Erratic Tests. So what are our options?
Briefly, our choices are to
• Remove the singleton nature
• Make no changes and live with testing a shared fixture
• Relax the constraints on instance
• Or relax the constraints on construction
Let’s take a look ...
Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.