J
Jean Lutrin
Hi all,
I have a question regarding an article written some
time ago by someone at IBM (in 2001), called
"Use your singletons wisely". Here's the article :
http://www-106.ibm.com/developerworks/webservices/library/co-single.html
Only people who already read that article or willing
to read it will be able to follow what's coming now
My question is not about the singleton, but about
an example that I really don't get.
At one point, after a sample unit test, the author writes :
"You may wonder why you shouldn't just specify a silly
file name to actually create the exception condition,
rather than simulate it. We're interested only in
simulating the exception condition, and not re-creating
it -- doing the latter more easily leads to confusion."
It was *exactly* what I was thinking when reading is example
source code.
I use unit testing (and code coverage tools btw) quite often
and I am completely puzzled by his example.
Basically, he adds a "fake" method to a MockDeployer called
doNotFindAnyFiles() instead of using a deliberately
non-existing filename, because he argues, rightly, that the
file, whatever crazy the name, could exists (this is debatable
btw, on an OS with file access permission -- Windows 2000, XP,
Linux, Solaris, whatever Un*x for what it is worth, -- it is
actually trivial to choose a filename that you'll be sure
won't able to be written).
But then what is his unit test testing ? The unit test is
suppose to test the correct behavior of the Deployer class
in the case where some file could not be written ?
Instead, as I understand the example, he is testing that the
"fake" method (which has no purpose other than pass the unit
test) called doNotFindAnyFiles() in his MockDeployer his
acting correctly ?
So in his MockDeployerClass he adds a test somewhere
which probably ressembles something like, say :
if (doNotFindAnyFilesFlag == true)
{
throw new FileNotFoundException(...)
}
How is that helping at all testing the "real" Deployer ?
As I see it, this is just adding unnecessary kludge to the
project : unnecessary unit tests (not testing the right
thing) and unnecessary methods in the MockDeployer (the method
doNotFindAnyFiles() as no purpose in the real Deployer) ?
But then I am surely completely wrong.
Please, help me, there's something that I really didn't
get in this paper (btw I did like the paper : but I have
this strange feeling that I didn't really understand
anything because of this example that I don't get).
Thanks in advance,
Jean
I have a question regarding an article written some
time ago by someone at IBM (in 2001), called
"Use your singletons wisely". Here's the article :
http://www-106.ibm.com/developerworks/webservices/library/co-single.html
Only people who already read that article or willing
to read it will be able to follow what's coming now
My question is not about the singleton, but about
an example that I really don't get.
At one point, after a sample unit test, the author writes :
"You may wonder why you shouldn't just specify a silly
file name to actually create the exception condition,
rather than simulate it. We're interested only in
simulating the exception condition, and not re-creating
it -- doing the latter more easily leads to confusion."
It was *exactly* what I was thinking when reading is example
source code.
I use unit testing (and code coverage tools btw) quite often
and I am completely puzzled by his example.
Basically, he adds a "fake" method to a MockDeployer called
doNotFindAnyFiles() instead of using a deliberately
non-existing filename, because he argues, rightly, that the
file, whatever crazy the name, could exists (this is debatable
btw, on an OS with file access permission -- Windows 2000, XP,
Linux, Solaris, whatever Un*x for what it is worth, -- it is
actually trivial to choose a filename that you'll be sure
won't able to be written).
But then what is his unit test testing ? The unit test is
suppose to test the correct behavior of the Deployer class
in the case where some file could not be written ?
Instead, as I understand the example, he is testing that the
"fake" method (which has no purpose other than pass the unit
test) called doNotFindAnyFiles() in his MockDeployer his
acting correctly ?
So in his MockDeployerClass he adds a test somewhere
which probably ressembles something like, say :
if (doNotFindAnyFilesFlag == true)
{
throw new FileNotFoundException(...)
}
How is that helping at all testing the "real" Deployer ?
As I see it, this is just adding unnecessary kludge to the
project : unnecessary unit tests (not testing the right
thing) and unnecessary methods in the MockDeployer (the method
doNotFindAnyFiles() as no purpose in the real Deployer) ?
But then I am surely completely wrong.
Please, help me, there's something that I really didn't
get in this paper (btw I did like the paper : but I have
this strange feeling that I didn't really understand
anything because of this example that I don't get).
Thanks in advance,
Jean