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

In general, you use an environment variable for this kind of behavior. I would strongly urge against it because that kinda negates the point of being tested. It sounds like you have an XY problem. You probably want to use some sort of mock object instead of having the module provide the mocking.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
  • 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:36 UTC
    As I explained above, the tests will remain the same, it is just the test-data to be inserted in the database that needs to be "manipulated" so they do not interfere with the real data. As the data are parsed out of external files I cannot change (since that would defeat the testing of the parsing routines) I thought it was a good idea to change some fields after the parsing but before the insertion. On second thought and as suggested elsewhere a testing database would solve all those problems nicely.

    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