0

I have some specific code that runs in debug mode and other code that runs on release mode. I'm trying to write some tests to ensure that only code that is supposed to run based on the configuration runs. Essentially, I have a set of interceptors that run in debug mode but not in release mode because it modifies the data a little for testing purposes.

How can I programatically change the configuration type?

Nosila
  • 540
  • 7
  • 20
  • What exactly do you mean? You want to know how to build code for different targets? – David Heffernan Feb 14 '12 at 17:27
  • Do you need your test code to determine whether the code under test was compiled in DEBUG/Release mode? [How to find out if an assembly was compiled with TRACE or DEBUG flag](http://stackoverflow.com/q/629674/33051) has a number of solutions to that problem. – Zhaph - Ben Duguid Feb 14 '12 at 17:31

2 Answers2

4

How can I programatically change the configuration type?

You can't. Write tests that will only be compiled in Debug, and others that will only be compiled in Release (using #if directives). e.g.

#if DEBUG

    [Test]
    public void DebugOnlyTest()
    {
        ...
    }

#else

    [Test]
    public void ReleaseOnlyTest()
    {
        ...
    }

#endif

    [Test]
    public void NormalTest()
    {
        ...
    }
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
1
#if DEBUG
            Text = "In Debug";
#endif

The middle line will be executed only in debug mode.

ispiro
  • 26,556
  • 38
  • 136
  • 291