Testing the Singleton Nature
Focusing on the singleton nature, there are two essential behaviors and two optional behaviors we need to test. The two essential behaviors are
• That getInstance() returns an instance of the class
• That getInstance() returns the same instance for all invocations
Let’s address these and then talk about the optional behaviors. Note that we did not say anything about the initialized state of the instance. That is not part of the value added by the getInstance() method. Rather, it is part of the value added by the class member initialization and the constructor, which are a separate bundle of intents.
The second behavior, that the singleton always returns the same instance, is the behavior that makes singletons difficult ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access