Does NUnit mean objects that implement IDisposable?

Does NUnit remove objects that implement IDisposable during cleanup? I understand that there are different ways in which I can get rid of an object in a method, but, for example, if the method failed before the object to be deleted, will NUnit take care of this? (For reference, I'm on v2.6 +)

The specific reason I'm asking is when an object that implements IDisposable is created, but I claim that an exception is thrown when created. If the test fails and the object is created, I do not want to run 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 understand that this will work:

Assert.Throws<Exception>(() => 
{
    using (StreamReader sr = new StreamReader(filename)) { }
}

But it just seems like unnecessary code if NUnit takes care of recycling when necessary.

+4
1

, NUnit . NUnit 3.x , IDisposable, .

, , NUnit , . , NUnit IDisposable, //, .

, Assert.Throws:

public static TActual Throws<TActual>(TestDelegate code) where TActual : Exception

, TestDelegate, . TestDelegate void,

public delegate void TestDelegate();

, StreamReader, , , , NUnit. NUnit , . , , .

+7

All Articles