At my normal job, I was recently put in charge of converting our NUnit tests to MSTest. After much researching online and reading lots of posts, here is the method that seemed to work for me.
- Remove dll references to NUnit.Core & NUnit.Framework.
- Add a reference to Microsoft.VisualStudio.TestTools.UnitTesting.
- In the code, find and replace:
- using NUnit.Framework; → using Microsoft.VisualStudio.TestTools.UnitTesting;
- [TestFixture] → [TestClass]
- [Test] → [TestMethod]
- [SetUp] → [TestInitialize]
- [TearDown] → [TestCleanup]
- [TestFixtureSetUp] → [ClassInitialize]
- [TestFixtureTearDown] → [ClassCleanup]
- (TestFixtureAttribute) → (TestClassAttribute)
- (TestFixtureSetUpAttribute) → (TestInitializeAttribute)
- (TestFixtureTearDownAttribute) → (TestCleanupAttribute)
- (TestAttribute) → (TestMethodAttribute)
- Update all of the Assert calls.
- The 'hidden' part. In your project file, locate <PropertyGroup> (not the one specifying debug|release settings), and add the following to it under <ProjectGuid>…</ProjectGuid>:
- <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
- Do not change the GUID. Visual Studio uses that exact GUID set to identify all Unit Test projects.
- In Visual Studio, go to the "Test View" and confirm that your tests are listed.
- If needed, change setup()→ public static void setup(TestContext context)
- If needed, change teardown()→ public static void teardown()
I'm posting this here for historical purposes. UnitTests can come in handy for all kinds of development and Visual Studio's built in testing makes it extremely easy to do. I know I'm guilty of not having many unit tests for my game, but as code becomes more and more mature, unit testing can make sure that we're not doing something we shouldn't. It's also a good way to make sure the build you're about to release to your players isn't going to destroy something vital, like Saved Games or existing map data.
No comments:
Post a Comment