I have a set of MSTest test cases that use methods with those attributes to delete all rows from tables in the test db created after the tests are started; every once in a while I end up with a row from a one of the unit tests still in the DB.
Since I'm saving the test start time and deleting all records with timestamps more recent than it, the only way I can see for the records surviving is if the cleanup code wasn't called.
Well, first off, a "unit test" technically shouldn't touch the DB. But, I use NUnit for my integration tests too, so no biggie.
The only circumstances in which the cleanup methods wouldn't run in their entirety is if there were an error in the cleanup function, or an exception caused the runtime to shut down. The only ones that I know can do that are stack overflow and out-of-memory errors. Aborting a test from the debugger will also cause the cleanup phase to be skipped.
A more likely explanation, depending on your data access layer, is that you lost your DB connection and the cleanup function couldn't get a new one. That would generally indicate a need to make your DAL more robust, and also indicates that something you're not expecting is happening in the test to cause the DAL to break down.
If you are debugging the tests and you stop the debugger before the test run completes, this will not be called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With