Originally posted by Vladas Razas:
How to test singleton creation with JUnit....
Juan Rolando Prieur-Reza, M.S., LSSBB, SCEA, SCBCD, SCWCD, SCJP/1.6, IBM OOAD, SCSA
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
Originally posted by Vladas Razas:
Ok circumvented problem by adding newInstance which is overriden by child class.
Juan Rolando Prieur-Reza, M.S., LSSBB, SCEA, SCBCD, SCWCD, SCJP/1.6, IBM OOAD, SCSA
Originally posted by J. B. Rainsberger:
http://www-106.ibm.com/developerworks/webservices/library/co-single.html
Juan Rolando Prieur-Reza, M.S., LSSBB, SCEA, SCBCD, SCWCD, SCJP/1.6, IBM OOAD, SCSA
Originally posted by john prieur:
Misuse of the Singleton does not mean there is something wrong with the Singleton design pattern, nor its testability characteristics (which is not the focus of that pattern's Problem or Context).
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
Originally posted by john prieur:
In your article you say, "Coupling among classes is vastly increased when classes know where to get instances of their collaborators."
Misuse of the Singleton does not mean there is something wrong with the Singleton design pattern
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Vladas Razas:
Also maybe there is a way to make JUnit start test as it where another application. I mean execute test in clean and fresh application context. Probably that would require restarting JVM and would be slow but you could specify only selected tests that need this feature.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Lasse Koskela:
By the way, wouldn't
be enough of a test for the singleton behaviour?
Juan Rolando Prieur-Reza, M.S., LSSBB, SCEA, SCBCD, SCWCD, SCJP/1.6, IBM OOAD, SCSA
Originally posted by Lasse Koskela:
By the way, wouldn't
be enough of a test for the singleton behaviour?
Originally posted by john prieur:
Sure, if the uniqueness of your Class is the only feature of the Class worth testing. But, Singletons can have lots of methods and attributes, and they should be tested as well.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Also maybe there is a way to make JUnit start test as it where another application. I mean execute test in clean and fresh application context. Probably that would require restarting JVM and would be slow but you could specify only selected tests that need this feature.
subclassing pattern of testing to test the Singleton. But I like it, and I like to use a uniform testing strategy.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Jeanne Boyarsky:
...
John,
As you can see in my thread, I don't really like subclassing to test if it isn't necessary. But if that is your strategy, I understand. ...
[ August 12, 2004: Message edited by: Jeanne Boyarsky ]
Juan Rolando Prieur-Reza, M.S., LSSBB, SCEA, SCBCD, SCWCD, SCJP/1.6, IBM OOAD, SCSA
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|