Should tests run in Debug or Release configuration in dotnet core
Asked Answered
J

2

27

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?

Jenny answered 30/1, 2019 at 8:50 Comment(0)
E
12

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.

Ednaedny answered 21/10, 2020 at 12:34 Comment(0)
U
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.

Unchancy answered 21/11, 2020 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.