Remove NUnit reference for Release build
Asked Answered
P

3

8

I have a project with many NUnit tests. I am happy for these tests to be included in the Debug configuration build but I would like to remove the dependency on nunit.framework for the Release configuration. Is there a way of excluding the NUnit reference and the nunit test objects for a specific (Release) configuration? I am using Sharp Develop but I am curious how you would approach this problem with Visual Studio as well.

Any clues?

Peatroy answered 31/8, 2011 at 14:23 Comment(0)
S
12

It sounds like you've got your tests in the same project as your release code. That's not a great idea - split the code into two projects, one with the tests and one with the production code. Only the test project will need to refer to NUnit.

That also means that none of the tests will ship with the release code, and it's easier to browse just the production code or just the test code.

Senghor answered 31/8, 2011 at 14:25 Comment(0)
D
5

If you prefer to develop with my Unit Tests as a part of the project you're trying to test, you can add the following condition to both your unit test files and your nunit reference in the project file.

Condition=" '$(Configuration)'=='Debug' "

That will only include the nunit reference as well as your test classes in the build when you're in debug mode.

So your project file might have something like this:

<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" Condition=" '$(Configuration)'=='Debug' ">
  <HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>

<Compile Include="UnitTests.cs" Condition=" '$(Configuration)'=='Debug' "/>
Destined answered 11/8, 2014 at 15:27 Comment(1)
leaving my answer in generic form, but my personal opinion has changed to be more in line with Jon's answer. On a larger team i think it's best to enforce a separate project for unit tests, as this will test your contracts the same as any other consumer would.Destined
T
1

Move your unit tests to a different assembly - i.e. YourProject.UnitTests

This won't form part of your deployment package, and there will be no need to include the nUnit reference in your main application.

Torruella answered 31/8, 2011 at 14:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.