How to Convert a Visual Studio 2005 non-Test Project to a Test Project

Have you ever been in the position where you want to convert an already existing Visual Studio 2005 project to be a Test Project so that you can write and run unit tests? There is no simple way, but there is a hack.

Assuming that you are using a version of Visual Studio that supports Testing (e.g. Team Edition for Software Testers) here is how to do it:

  1. Add the following .NET Reference to the project:
  2. Put in the following using directive in the .cs file that contains your tests:
    using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. Create a Test List, this will generate the .vsmdi file (This is the file that opens your Test Manager tab):

    1. Click Test in the top menu
    2. Select Create New Test List:

    3. Notice in the Solution Explorer that the Project now is wrapped in a Solution and the .vsmdi file has been created:

  4. Setup your test configuration file (.testrunconfig):

    1. In Solution Explorer right click the Solution Items folder, select Add, then select New Item
    2. In the dialog, highlight Test Run Configuration on the left and select Test Run Configuration on the right side
    3. Name the file accordingly and then click Add:
    4. Notice the .testrunconfig file has been added to the solution

  5. Close Visual Studio
  6. Open the project’s .csproj file in a text editor.
  7. In the top <PropertyGroup> node, change the <ProjectTypeGuids> node to read:

    If your using VB.NET your GUID should be:

  8. Save and close .csproj file.
  9. Open the Solution up (.sln file).
  10. You are now ready to write tests.
  11. To run your tests:

    1. In Solution Explorer double click the .vsmdi file to open the Test Manager window
    2. Check the test you want to run
    3. Right mouse click the test and select Run Checked Test.


This problem is quite interesting due to the fact that the .vsmdi file and .testrunconfig exist at the Solution level and not the Project level. In the past this interesting fact was a small hurdle for our automation team because we needed to create a Visual Studio template for a Test Project, but Visual Studio only templates Projects and not Solutions (again the .vsmdi & .testrunconfig need to exist at the .sln level). I’ll save the explanation of that workaround for another day!

One Response to How to Convert a Visual Studio 2005 non-Test Project to a Test Project

  1. Patrick Stevens says:

    Thanks for the insight. Do you plan on showing your work-around for creating a test project template (complete with Solution level vsmdi and testrunconfig files)? I would be interested to hear how you were able to accomplish it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.