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. On Thursday 11 January 2007 18:54, Ovid wrote: > Well, as a general rule, one wants to minimize any reliance on > knowledge of testing in one's code, that is an understatement. > but the fact remains that 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 (this tends not to be the case with clean code). Thus, when one > has really bad code that shouldn't be run while testing, it can be > useful to have such an environment variable. > Note that I see no problem with testing hooks which make code easier to > override, but code shouldn't have knowledge of tests per se. That > being said, in the real world, it's not always practical to avoid this, > particularly when you are adding tests to an old, untested code base > and you need to get tests in place prior to refactoring. 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. I've never seen any requirement that says: "when testing, don't do this and that". 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. 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. If someone would ask me, I'd vote for removing that feature alltogether. It might make it more difficulte to be "practical and wrong" but I would live with that. Nadim, the devil's advocate :)