7

While working on ASP.NET MVC3 application, by mistake I have added a Class library as a Unit Test project. But unfortunately I don’t see the "Run Tests" from context menu to test the methods which are created for unit testing .

Is there any way to convert the “Class Library Project” into a “Test Project” ?

Padmalochan
  • 1,070
  • 1
  • 11
  • 21

3 Answers3

3

Just add Microsoft.NET.Test.Sdk from nuget.

Soleil
  • 6,404
  • 5
  • 41
  • 61
Ankita Singh
  • 579
  • 6
  • 7
2

There is a property type guid in the project file. Look at this post: How does Visual Studio /mstest identify test projects?

Community
  • 1
  • 1
Marian Ban
  • 8,158
  • 1
  • 32
  • 45
2

What worked for me was to do add this <PropertyGroup> tag with this libraries to my project (.csproj or .vbproj) file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
    <PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
    <PackageReference Include="coverlet.collector" Version="1.3.0" />
  </ItemGroup>

<!--Here goes any other configuration-->

</Project>
Diego Arias
  • 171
  • 2
  • 14