Visual Studio 2013 Modifies NUnit Project Files

2014, Oct 16    

I've seen this several times now and an issue was just reported against the NUnit Visual Studio adapter, so I thought I would document my findings on this.

If you run non-Microsoft unit tests in Visual Studio using a test adapter, Visual Studio 2013 will modify the project file and add the following lines.


  

This happens for NUnit, XUnit and other 3rd Party test adapters. This behavior is a new feature of Visual Studio 2013.

In this issue on Connect, Microsoft says it is intentional and provides what I see as a less than ideal workaround.

Posted by Microsoft on 10/24/2013 at 7:38 AM

This behavior is intentional.

To support third-party test frameworks, like NUnit and XUnit, Visual Studio 2012 loaded Test Explorer on solution open, regardless of whether it contained test projects. This added seconds of delay to startup and solution open scenarios for all users, majority of whom don't use tests.

In Visual Studio 2013, we changed it so that Test Explorer package is loaded only when the solution contains one or more test projects. Test projects are identified in two different ways. Projects created from one of the built-in unit test project templates are identified using project type GUIDs. Other types of projects, such as Class Library project with XUnit or NUnit tests, are identified by Test Explorer during first test discovery and tagged with the Service/item.

You can avoid Visual Studio automatically adding the Service/item to your test projects by creating them from any of the built-in unit test project templates. In other words, select the "Unit Test Project" template instead of the "Class Library" template in the New Project dialog.

If you want to change existing projects from a "Class Library" to a "Unit Test Project", edit the project file and add the following to the first PropertyGroup

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

This isn't much different than the Service being added, but maybe it is more correct because it is a test project?

Unfortunately, this doesn't work if anyone is using Xamarin studio since the Unit Test Project type is not supported.