Testing database/data layer without using Singleton method
Mark O' Sullivan
posted 6 years ago
Just wondering if I don't use the Singleton pattern for the Data layer of my project, for testing purposes, would I have to use multiple instances of my Data class in testing? For example, say I was testing multiple-threading of 50 reads. Would I need to say, test 25 of these using 1 instance of my Data class and another 25 say using another instance? Basically what I am asking is if one does not use the Singleton pattern for the Data layer when accessing the database functionality, do they have to test application across multiple instances of the data class?
That all depends on how you implemented concurrency and making the data class thread-safe. Many possible alternatives to ensure thread-safety, so it has little added value to elaborate on it.
And if you implemented your singleton pattern correctly, you should not be able to create multiple instances of your Data class. Because if you can do it for testing purposes, you also can do it for developing (production) purposes and the singleton pattern is not applied correctly.