Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should tests run in Debug or Release configuration in dotnet core

I am using dotnet core 2+, but the question is likely much more generic.

My CI pipeline currently looks like this:

  • dotnet build -c Release
  • dotnet test
  • dotnet public -c Release --no-build

For the test step, it uses the default Debug configuration, therefore it also has to build the app using Debug config.

Therefore, I was wondering, whether there is any advantage in running tests using Debug rather than Release or should i just simply add dotnet test -c Release?

like image 795
eddyP23 Avatar asked Jan 30 '19 08:01

eddyP23


People also ask

Does Release run faster than debug?

Lots of your code could be completely removed or rewritten in Release mode. The resulting executable will most likely not match up with your written code. Because of this release mode will run faster than debug mode due to the optimizations.

What is the difference between debug and Release mode?

Debug Mode: When we are developing the application. Release Mode: When we are going to production mode or deploying the application to the server. Debug Mode: The debug mode code is not optimized. Release Mode: The release mode code is optimized.

What are debug and Release build configurations?

A Debug configuration supports the debugging of an app, and a Release configuration builds a version of the app that can be deployed.


1 Answers

I believe it's possible to choose by comparing of the differences between "Debug" and "Release".

In Release mode: there are compiler's optimizations. Compiler does some low-level improvements. This leads to original code can be changed significantly in some places. (some variables and methods calls can be optimized in a non obvious way).

In Debug mode: code is not optimized, and along with final assemblies compiler produces .pdb files with are used for a step by step debugging.

As a conclusion, for tests, is better to use Release mode:

  1. It is lighter than Debug (.pdb files are not needed).
  2. It is faster that Debug (due to compiler's optimizations, .pdb files are not generated).
  3. Tests are run against prod like environment.

P.S. Along with that keep an eye on preprocessor directives and config transformation if they are presented, and depend on build configuration.

like image 107
Artem Alieinikov Avatar answered Oct 04 '22 01:10

Artem Alieinikov