in reply to How to make a module aware it is being tested?

I'm sort of with others on this. I'd be reluctant to test for file existance, or some of those other things. I think it's better to set/get a test variable when you call it for test mode.

It sounds like this isn't for public consumption (since you mentioned sticking test records in a database). If that's the case, then I'd definitely just have a test variable you can set for unit testing. This may cause you to write some wrapper subs that do the test and return strings based on whether the test was set.

Also, I'd recommend some immediate output (to log or whatever you use) indicating that the module is acting in TEST mode. You really don't want to push that out to prod and end up with test crap in your database.
--
I used to drive a Heisenbergmobile, but everyone I looked at the speedometer, I got lost.
  • Comment on Re: How to make a module aware it is being tested?

Replies are listed 'Best First'.
Re^2: How to make a module aware it is being tested?
by CountZero (Bishop) on Nov 02, 2007 at 09:41 UTC
    You really don't want to push that out to prod and end up with test crap in your database.

    All too true, hence my initial idea to have the module check whether it was being tested or not. When in testing mode it would insert data records with a clearly identifiable "TEST" mark which would be easy to remove even if the test totally crashed and did not clean-up at the end.

    But I'm now convinced that a test database is probably the better choice.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James