Throwing Development Muses

Monday, June 27, 2005

Converting NUnit tests to Visual Studio 2005 Tests

I've been looking at this recently, and there is no easy way at the moment (yet, James Newkirk is developing one here).

But I have discovered the following:

Once you have converted your project to VS2005 you will have to add a reference to the Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly to your project containing the nunit tests.

Having done this you might expect VS2005 to recognise the project as a test project, but it doesn't, and your tests don't appear in the test manager.
To get VS to do so you have to edit the .csproj file manually and in the top section add the following:

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

These GUIDs identify the project as a c# test project.

Then its generally a Find|Replace procedure to replace the attributes etc. in your test classes.

Here are the ones that I have had to change:

Declarations:

  • using NUnit.Framework becomes using Microsoft.VisualStudio.QualityTools.UnitTestFramework


  • Attributes:

  • [TestFixture] becomes [TestClass]

  • [TestFixtureSetUp] becomes [ClassInitialize]

  • [TestFixtureTeardown] becomes [ClassCleanup]

  • [Test] becomes [TestMethod]

  • [Test (Description="text here")] becomes [Test] and [Description("text here")]

  • [Ignore("some text here")] becomes [Ignore]


  • Other:

  • ExpectedException attribute stays the same.

  • Descriptions can't be placed at class level.

  • Test defined in abstract classes cannot be run.

  • 0 Comments:

    Post a Comment

    Subscribe to Post Comments [Atom]



    << Home