简体   繁体   English

在构建服务器上进行单元测试:发布还是调试代码?

[英]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? 在.NET(C#)中,进行单元测试的调试/发布版本是否有优点/缺点?

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. 1)这是客户将使用的代码。

2) Some code has special debug conditionals that will produce differences between the debug and release builds. 2)一些代码具有特殊的调试条件,这些条件会在调试版本和发行版本之间产生差异。

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. 在大多数合理的部署方案中,将在Release配置中编译代码。

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". 例如VS调试代码中的afaik,未初始化的变量被强制为某个可怕的值,而不是“偶然”为0。 Maybe in .NET it does not make a big difference, but for me, doing mainly algorithmic core code in C++, this can be crucial. 也许在.NET中并没有太大的区别,但是对于我来说,主要是在C ++中执行算法核心代码,这可能至关重要。

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. 即使测试本身是绿色的,即使遇到Debug.WriteLine()调用,某些CI服务(Appveyor)也会使构建失败。

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

We are running both, Debug + Release. 我们同时运行Debug + Release。

We output a separate tests results xml for each build. 我们为每个构建输出单独的测试结果xml。

Sometimes there are errors in Debug only, and sometimes in Release only, you want to catch them all ASAP. 有时仅在Debug中有错误,有时仅在Release中有错误,您希望尽快捕获所有错误。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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