Remove NUnit Link for Release Build

I have a project with many NUnit tests. I am happy that these tests will be included in the Debug configuration assembly, but I would like to remove the nunit.framework dependency for the Release configuration. Is there a way to exclude the NUnit link and nunit test objects for a specific (Release) configuration? I use Sharp Develop, but I'm curious how you could address this issue with Visual Studio.

Any clues?

+8
source share
3 answers

It looks like you have your tests in the same project as your release code. It is not a great idea to split the code into two projects: one with tests and one with production code. Only a test project will have to reference NUnit.

This also means that none of the tests will come with a release code, and it’s easier to see only the production code or only the test code.

+12
source

If you prefer to develop my unit tests as part of the project you are trying to test, you can add the following condition to the unit test files and a link to nunit in the project file.

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

This will only include a link to nunit, as well as your test classes in the assembly when you are in debug mode.

So your project file may 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' "/> 
+5
source

Move device tests to another assembly - i.e. YourProject.UnitTests

This will not be part of your deployment package, and there is no need to include the nUnit link in the main application.

+1
source

Source: https://habr.com/ru/post/896330/


All Articles