简体   繁体   中英

Unit testing on a build server : Release or Debug code?

In .NET(C#) is there any advantage/disadvantage to go with debug/release build for unit testing?

Which target configuration do you usually use for unit testing on a build server? Does it matter?

What about code coverage (for this one I'm guessing debug versions are needed).

I'd recommend running the release code. For a couple of reasons.

1) It is the code that the customers will be using.

2) Some code has special debug conditionals that will produce differences between the debug and release builds.

You must test the code the way it will ultimately run on the client's machine. In most sane deployment scenarios that will be code compiled in the Release configuration.

Despite most people obviously favour to unit test the release code, I wonder whether the debug build might uncover more errors, though. (I might be wrong)

Eg afaik in VS debug code, uninitialized variables are forced to some awful value instead of being 0 "by accident". Maybe in .NET it does not make a big difference, but for me, doing mainly algorithmic core code in C++, this can be crucial.

I look forward to any enlightening comments ;).

I would use release build when possible, to get everything as close to the final product as possible.

There are small differences between debug mode and release mode that normally only make a difference for performance, but not result. However, if there is some timing problems with the code they may only show in release mode, so you could take the opportunity to possibly catch those.

Just adding another reason to test in release mode. Some CI services (Appveyor) will fail the build if it comes across a Debug.WriteLine() call, even though the test itself is green.

测试调试代码时,(对我而言)更容易找到异常的根源。

We are running both, Debug + Release.

We output a separate tests results xml for each build.

Sometimes there are errors in Debug only, and sometimes in Release only, you want to catch them all ASAP.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM