Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Visual Studio /mstest identify test projects?

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?

like image 350
Nilzor Avatar asked Aug 10 '11 11:08

Nilzor


People also ask

Is MSTest a testing framework?

MSTest is a number-one open-source test framework that is shipped along with the Visual Studio IDE. It is also referred to as the Unit Testing Framework. However, MSTest is the same within the developer community. MSTest is used to run tests.

Does TestInitialize run for each test?

TestInitialize and TestCleanup are ran before and after each test, this is to ensure that no tests are coupled. If you want to run methods before and after ALL tests, decorate relevant methods with the ClassInitialize and ClassCleanup attributes. Save this answer.

Which attribute should be used to mark a method as test method in MSTest testing?

The TestClass attribute denotes a class that contains unit tests. The TestMethod attribute indicates a method is a test method.

How vs test Live code?

Start Live Unit Testing by selecting Test > Live Unit Testing > Start from the top-level Visual Studio menu. You can also open the Live Unit Testing window using View > Other Windows > Live Unit Testing Window.


2 Answers

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#).

like image 152
J. Steen Avatar answered Oct 10 '22 00:10

J. Steen


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.

like image 29
jwg Avatar answered Oct 10 '22 00:10

jwg