Often a test will execute a “cleanup” method to delete items (often out of a database) that were created or used in the test, to make sure the next test has a clean environment to run in. Sometimes though, the cleanup never gets run – if it is the last thing to run (as would seem logical), if there is a test failure it will never execute.
A better option is to run the cleanup method at the beginning of a test. If the method simply executes SQL scripts to delete records, if the records for some reason aren’t found, it won’t generate any kind of error, so the script will run normally. However, doing it this way (putting the cleanup at the beginning) insures the data cleanup will get executed on every test, insuring a clean environment for every test that gets run.
No comments:
Post a Comment