Create Unit Tests: default template & IDisposable

When using the Create Unit Tests dialog, the generated code doesn't properly call Dispose on my disposable class. Is there a way to modify the code template used by this command?

The style I've developed for dealing with this is to add a member variable to the test class for the target, and put initializaiton of it in a [TestInitialize] method, and call Dispose in the [TestCleanup]. This keep the [TestMethod]'s lean and easy to maintain, and the cleanup method gets called even if the test fails.

[656 byte] By [BurtHarris] at [2007-12-24]
# 1

Unfortunately we don't have code template that you described for test generation and I don't think there is an any easy workaround other then what you have done. What you have asked is a good suggestion and I would recomment to enter a product feedback through our feedback web site (https://connect.microsoft.com/VisualStudio/feedback/) so our product team can review it for future feature consideration.

Thanks,

Bata Chadraa, VSTT

bchadraaMSFT at 2007-10-8 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 2

Just another idea for workaround is to include your target instantiation around using statement where in the exit of that statement Dispose() is guaranteed to be called.

For example:

[TestMethod]

public void Test()

{

using(Class1 target = new Class1())

{

// Your test goes here

}

}

Let me know if you question was regarding to test class that implements IDisposable interface.

Thanks,

Bata Chadraa

bchadraaMSFT at 2007-10-8 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...

Visual Studio Team System

Site Classified