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

My use case is as follows:

I get external files which I need to parse to extract the data I have to save into a database. I cannot change these external files as that would invalidate the testing of the whole parsing process.

The next step is to save this data into the database, BUT

Hence my idea to change the primary keys of the data to be inserted, so

For that to work I had thought it would be easiest if my module would "know" when it was being tested, so it could manipulate the test data as explained above. Rather than relying on environment variables, external semaphore files or additional attributes on the module's object (all of which a programmer might forget to set or provide), I was looking for a solution which could be built-in, but it seems there is no easy fool-proof automatic way to check if a module is being "tested".

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

  • Comment on Re^2: How to make a module aware it is being tested?