Reputation: 18603
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:
Anyone?
Upvotes: 19
Views: 12318
Reputation: 11
The GUID solutions did not work for me in VS 2022. Turns out all I needed to do was edit the project file and add the IsTestProject value:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{553487BF-FC0B-4FC5-B25B-C8C89A13F4ED}</ProjectGuid>
<IsTestProject>true</IsTestProject>
<OutputType>Library</OutputType>
.
.
.
</PropertyGroup>
Upvotes: 1
Reputation: 15588
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#).
Upvotes: 36
Reputation: 5847
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.
Upvotes: 4
Reputation: 1090
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>
.
Save the changes, right-click the project, and then select Reload Project.
Upvotes: 4