Since Team System unit tests are now available in Visual Studio 2008 Pro, it is convenient to be able to use this rather than rely on a 3rd party add-ins to support NUnit. On the other hand, it is good to have backwards compatibility with NUnit so that code could be built outside of VS, or in VS Express edition.
There is a pattern that Microsoft has been using to allow this, involving conditional compilation: place this at the top of a project file:
#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
#endif
The two APIs are not exactly the same but there is a useful subset of Assert methods that will work in both.
0 comments:
Post a Comment