by kkikta
4. December 2009 04:16
If your like me you have done some unit testing but your not crazy about writing tests for everything because well you could be writing functional code. I'm not gonna argue that testing isn't necessary or that you should do it all the time. Personally I have found it extremely useful especially when testing components that are not full fledged programs but find it to be a bit unnecessary in many situations.
So you have been using NUnit to do your tests and it works great but with Visual Studio 2010 (and i think 2008) Microsoft built in a testing framework that's available to users of Team System and Professional. So you figure if I'm converting my project then why not convert my tests as well. It makes sense especially since its a pain when I work with someone on a project and they don't know about NUnit and complain that they have to install it, add the reference and all that jazz. So I am putting together a list of steps to do the conversion below.
- Unload your test project from the solution.
- Open up your project file(.cspro) in notepad (or your text editor of choice.)
- Find the first section of xml containing the following tag <PropertyGroup>.
- Inside the <PropertyGroup> tag add the following:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>- {3AC096D0-A1C2-E12C-1390-A8335801FDAB} means test project.
- {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} means 2008 solution.
- Reload the project.
- Change your reference from nunit.framework to Microsoft.VisualStudio.QualityTools.UnitTestFramework
- Add the following to you test classes
using Microsoft.VisualStudio.TestTools.UnitTesting; - Remove NUnit's names space from the classes (using NUnit.Framework;)
- Make the following changes to your class and method attributes:
- [TestFixture] becomes [TestClass]
- [TestFixtureSetUp] becomes [ClassInitialize]
- [TestFixtureTearDown] becomes [ClassCleanup]
- [SetUp] becomes [TestInitialize]
- [Test] becomes [TestMethod]
- [TearDown] becomes [TestCleanup]
- Close the solution and reopen it.
So far that seems to be about it. All in all a pretty easy change. If I find more I'll update. Also there is a tool that is supposed to do the conversion for you
here but I prefer to know whats happening vs. using a tool blindly.
34574d77-08d5-4ea3-87cc-d968d20f440e|0|.0
Tags:
.NET | General