Nadim Khemir writes:

> On Thursday 11 January 2007 18:04, Ovid wrote:
>
> > > Just one, Shouldn't the mailer "object" be mocked and the mail
> > > sending checked?
> 
> > absolutely, but how do you know to mock it or really send the email
> > unless you know that you're being run by tests?
> 
> Aren't you mixin contexts here? The code to be checked is sending mail
> (right?). The test framework mocks the mail object so only the test
> code needs to do something special and I believe the test code knows
> the test code is running.

You're assuming that the mail-sending code is an object, and separate
from other things that should be run in the test.  In bad code (which
Ovid stated this is) those aren't reasonable assumptions to make!

> > ... when one is working with ugly code, sometimes it can be very
> > difficult to refactor complicated bits out so that they can be
> > easily overridden by tests
> 
> Yeah, you have a bunch of ugly code and the best way is to make it
> even more ugly by making it aware of the testing.

Sometimes.  At least in the short term.

> I've never seen any requirement that says: "when testing, don't do
> this and that".

Me neither.  But I've seen lots of requirements that don't make any
mention of testing at all.  And lots of code that doesn't even have any
requirements about anything.

But suppose some code does a bunch of processing and then finally
interacts with the outside world in some way (sending an e-mail,
completing a financial transaction, controllig a robot) during testing
it may be readily apparent that it would be disruptive to have that
action occur.

> I'm actually wondering if code which has knowledge of it being tested
> is testable at all! well ' it's not. because you can never test the
> "send mail" feature.

Sure.  But you can at least test everything else, all the processing up
to the point which sends the mail.  And you could in the test
environment put the data that would be in the mail somewhere else, which
can be tested, so that just leaves the actual mail transport being
untested -- and that's probably being done with a Cpan module or
something which has been tested elsewhere.

> I'm sure you're not inventing this but one actually made the code
> worse whith that kind of hack.  IMHO, just enabling this kind of code
> is going against everything you want to achive, testable applications.

No, it's enabling you to test other code that is near an action which
absolutely cannot be run in a test environment, thereby making more of
the application testable.

Smylers

Reply via email to