24

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?

eddyP23
  • 6,420
  • 7
  • 49
  • 87

2 Answers2

8

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.

1

Do not use Debug mode if you are not going to debug your tests. Sometimes, people need debugging the app through the tests or even debugging the test itslef. If this is not the case, go with Release mode, it is lighter.

Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126