views:

345

answers:

3

I have been told that the automatically generated tests in VS2008 can be made compatible with NUnit just by adding

#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;
  using TestContext = System.String;
  using DeploymentItem = NUnit.Framework.DescriptionAttribute;
#endif

EDIT: The question slightly changed focus since i fixed the reference issue. Again, I was told this statement would work to change to the correct unit test program, VS or NUnit.

It never goes into the else statement. So the new question is, do i need to change the conditional to something else, or am I missing something simple again?

+2  A: 

Have you referenced the NUnit assembly in place of the VS testing assembly?

Richard
A: 

Are you trying to convert your tests or run both NUnit and VS tests in the same project? If you're converting then you should be able to use find & replace to make most of the changes.

I went through a conversion from VS tests to NUnit and found one syntax difference: The argument order is different for the IsInstanceOfType method.

Jamie Ide
A: 

Well I found out what to do after I overlooked the simple mistake Richard pointed out to me.

Since I am running these in CC.NET I just took the easy way out for the variable and set a windows variable in cmd and then ran the dll with nunit-console.exe.

If you don't really care about being able to swap back and forth between VS2008 and NUnit testings programs you can just take out the precompile code, leaving the contents of the if for VS and the contents of else for NUnit.

Jared