I suggest deciding this on a per-test basis:
Redefining
A simple sample: We had a function for error handling which could trigger three levels of action. When running tests and forcing some errors to check if they're detected, many lines were written to the error log on our dev server (no problem), many mails were written to our dev group postbox (annoying) and sometimes even emergency-procedures were started (cost money).
We solved this by redefining the actual error handling function in the test script:
(I know, this doesn't use modules, but there shouldn't be any difference.)[...] # Init tests, prepare everything, etc. require 'error.inc'; # Here are the regular handling functions defined +, Log_Error is one of them our $ErrorText; our $ErrorLevel; eval { sub Log_Error { ($ErrorText,$ErrorLevel) = @_; return 1; } };
# for expected errors: ok($ErrorText eq 'foo','Error-checking'); ok($ErrorLevel eq 'mail','Error-level-checking'); # for tests which shouldn't trigger one: ok($ErrorText eq '','Check for errors');
Test-DB Create a environment specially for the test. If you're using SQL, make the DB name or table name(s) configurable and overwrite the configured values with fixed values for the test. Use the DB/environment creation functions you created for your project, so your test environment will be up-to-date everything. Drop everything which is created automatically after running the test. This may be done by "DELETE * FROM Test_Table" which should be easier than searching a real table for the test-created records.
Make tests self-defining In few cases, you could read things from your systems parameters or databases and make your tests behave based on the things read. I don't have a good example in mind right now, but just think of a test checking for the number of configuration options written to a config file: The test will change each time you add an option, but if you have a reliable source for the options, you could read the list and check if every option defined is really written. This would change the number of tests dynamically, but this is possible. No a good sample, sorry.
Finally, the answer in most cases should be yes: You need to change your tests on many system changes. More tests mean less trouble, but means updating more files when changing something.
In reply to Re: Help with design philosophy II: Testing
by Sewi
in thread Help with design philosophy II: Testing
by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |