How does Visual Studio /mstest identify test projects?
Asked Answered
P

3

19

Say (100% hypothetically) that I've accidentally added a unit test project as project type "Class library" to a VS2010 solution. I've then added the assemblies needed to run it as a Unit Test project, but MSTest won't pick up on it when I hit "Run all tests in solution". What are the criterias here?

I had a couple of theories, which all have failed so far:

  • Something in the .testsettings file (no references to any assemblies here as far as I can see)
  • Something in the .SLN file (can't find anything)
  • Something in AssemblyInfo.cs (no, it's not)
  • Implict by referencing the (...)UnitTestFramwork.dll (Obv not)

Anyone?

Pilsner answered 10/8, 2011 at 11:21 Comment(0)
Z
34

In the project file, there's an XML element with the name ProjectTypeGuids, that holds a few GUIDs that denote test project. Example as follows.

<Project>
  <PropertyGroup>
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  </PropertyGroup>
</Project>

Here's a list of known project type GUIDs for Visual Studio 2010: http://onlinecoder.blogspot.com/2009/09/visual-studio-projects-project-type.html

In the example above, it shows the project to be of type Test and Windows (C#).

Zacynthus answered 10/8, 2011 at 11:36 Comment(2)
I found to get the flask icon, I also needed to add <TestProjectType>UnitTest</TestProjectType>Keyhole
FWIW, this is still the case 10 years later with VS2019Vain
H
4

In case it helps anyone I had the opposite problem - I added a project as Unit Tests mistakenly. To change the type back to a normal Class Library I just removed the ProjectTypeGuids tags mentioned in the other answers altogether, presumably VS put back the correct ones.

Harville answered 12/4, 2013 at 14:46 Comment(0)
M
3
  1. In Solution Explorer, right-click the project name and select Unload Project.
  2. Then right-click the project name again and select Edit ProjectName.csproj.
  3. Locate the ProjectTypeGuids element and following code.(If you will not find the ProjectTypeGuids element, just insert it)

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

  4. Save the changes, right-click the project, and then select Reload Project.

Maryannemarybella answered 29/5, 2012 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.