If I mark a cleanup function with the [TestCleanup] attribute in MSTEST will it ALWAYS run, even if there is an unhandled exception in my code? Is there anything that would cause this code block NOT to run? I have set this up and tested it and it seems to always run the cleanup but I want to make sure that I am not missing something.
Share
If your test throws an exception, the [TestCleanup] code will run.
The only thing I’ve found that will cause TestCleanup to not run is an unmanaged access violation. That ends up taking down the entire MSTest process. But pretty much anything in managed land will be OK, and the TestCleanup will run.
Obviously, anything that can terminate that process will make the TestCleanup not run, as was mentioned in the comments, e.g., power lost, hard drive failure, etc.