Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an existing assembly to a ms unit test assembly?

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 ?

like image 460
Patrice Pezillier Avatar asked Jun 10 '10 07:06

Patrice Pezillier


People also ask

How do I create a unit test in Visual Studio?

From the code editor window, right-click and choose Create Unit Tests from the right-click menu. The Create Unit Tests menu command is only available for C# code. To use this method with . NET Core or .

Which is better NUnit or MsTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.


1 Answers

The problem is that test projects are "marked" on the project file - you can convert a class library to Test project follow these four simple steps:

  1. Unload the project (.prj) file and then open it for update.
  2. add the following line to the project
    C#:

    <Project>  <PropertyGroup>   <AssemblyName>....</AssemblyName>   <!-- add this line below -->   <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>  </PropertyGroup> </Project> 

    VB - <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F- 5ABD9991F28F}</ProjectTypeGuids>

  3. Re-load the project back
  4. Run you (now working) tests

Note that you'll need to manually add reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll in order to be able to use test related attributes

Update: In the upcoming MSTest V2 this will not be nesessery as MSTest becomes a NuGet package which works just like NUnit/XUnit

like image 109
Dror Helper Avatar answered Oct 08 '22 17:10

Dror Helper