views:

772

answers:

2

Hi, I would like to switch between NUnit and VS Tests like this:

#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

My question is, how may I declare NUNIT preprocesor symbol at one place (App.config or so, would be great), to switch between NUnit and VSTests easily? Because when I use "#define NUNIT", it works only for the file, where it is written.

+3  A: 

Use the project properties dialog. You can define global symbols there:

Right click on the project -> Properties -> Build tab -> Conditional compilation symbols

Mehrdad Afshari
+4  A: 

The only way to do this per project is via the project / build itself (project properties -> build -> conditional compilation symbols). You can define multiple "configurations" for a project (with different symbols defined), and use the one you want.

To add a new configuration, use the configuration manager (at the bottom of the debug/release drop-down) and create a new one based on on of the existing (debug/release/etc). Now in the project properties you can choose this option to set the different symbols for that config.

Marc Gravell