It’s a general consensus that Singleton is bad for unit-testing.
But what about having an IoC container like the Spring framework to control your beans which are singletons by default? Is using those beans in your classes also considered bad for unit testing the same way singleton is?
Singletons are not a bad thing. They are very much a good thing.
The Singleton Design Pattern, however, is generally considered bad, since it can hamper testing.
When you have an IoC framework like Spring to manage your singletons for you, you're fine.
Spring proves a unit testing framework which manages singletons during the test lifecycle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With