Does NUnit dispose of objects that implement IDisposable on cleanup? I realize there are various ways I can get an object disposed of in a method, but, for example, if the method fails prior to the object being disposed - will NUnit take care of it? (For reference, i'm on v2.6+)
The specific reason i'm asking is for a case where an object that implements IDisposable is created, but I am asserting that an exception is thrown upon creation. If the test fails - and the object is created, I do not want to run into memory leak problems.
Example:
//Will the StreamReader instance here be disposed
//Of if the assertion fails, and the instance is created?
Assert.Throws<Exception>(() => new StreamReader(filename));
I realize that this will work:
Assert.Throws<Exception>(() =>
{
using (StreamReader sr = new StreamReader(filename)) { }
}
But it just seems like unnecessary code if NUnit will take care of disposing when necessary.