views:

30

answers:

2

In Visual Studio 2010 Pro, how can I easily convert a classic assembly to a ms unit test assembly ?

It there a flag to activate in the .csproj file ?

A: 

Unit Test Project is only Class Library which have classes with attribute [TestClass], and .csproj file doesn't have any flags. You can add class to your project and set attribute [TestClass] and it will be test class.

Pavel Belousov
Ok, but I want to start unit test in Visual Studio 2010. Even if I add a reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework and in my class i use [TestClass] and [TestMethod] attribute, I can't view my methods in the Test View window in VS2010.
Patrice Pezillier
You might have to build the code first before the methods appear in the window. Simply adding the attributes to the code, and not building, does not update the test view window (I think!).
Jason Evans
I made a rebuild all, but it doesn't work.
Patrice Pezillier
+2  A: 

Hi there.

I'll be honest, your question doesn't make sense as such. Do you mean you want to convert a "classic" (e.g. .NET 2.0?) assembly into an MS Test assembly? The only way to do that is manually change the code in VS 2010.

To do this you will need to add a reference to:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

and import the Microsoft.VisualStudio.TestTools.UnitTesting namespace. Then, your classic assembly, you need to mark your code like this:

[TestClass]
public class YourTestClass
{

   [TestMethod]
   public void Test(){}
}

Using the MS Test attributes that you need.

EDIT: Doh!!! I gave you the path to wrong file, it should be:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies

Cheers. Jas.

Jason Evans
I had already tried that but it doesn't seem to work. I can't view my methods in the Test View window in VS2010.
Patrice Pezillier
OK, I think you're going to have to create a new Test project from scrattch in VS. Go to the File menu and create a new test project. You will see a Class1.cs fiel created for you, simply copy and paste your code into that file and clean it up to get it working. Hope this helps.
Jason Evans
Ok but I wonder how and where unit test informations are saved for VS2010...
Patrice Pezillier