使用dotCover不一致时,测试结果 [英] Inconsistent test results when using dotCover

查看:701
本文介绍了使用dotCover不一致时,测试结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code与传递调试版本,但无法在一个发布版本是正确的单元测试。然而,同样的测试通过在两个调试和使用JetBrains的dotCover运行时释放模式

I have some code with unit tests that pass in a Debug build but fail in a Release build which is correct. However, the same tests pass in both Debug and Release mode when run using JetBrains dotCover.

要给出一个有点背景,这里是有问题的考验code,只是给你的,为什么它的失败的发布版本的想法 - 这是因为减少了堆栈信息基本都来自于code优化。

To give a bit of background, here is the offending test code, just to give you in idea of why it's failing for a Release build - it's basically because of reduced stack information due to code optimization.

using System.Diagnostics;
using NUnit.Framework;

namespace DotCoverTest
{
    [TestFixture]
    public class TestLogger
    {
        [Test]
        public void GetCurrentClassLoggerReturnsLoggerWithOwningTypeName()
        {
            Assert.AreEqual(Logger.GetCurrentClassLogger(), GetType().Name);
        }
    }

    public class Logger
    {
        public static string GetCurrentClassLogger()
        {
            return new StackFrame(1, false).GetMethod().DeclaringType.Name;
        }
    }
}

编辑: 任何想法如何,我可以设置我的生成,使我得到同样的测试结果有或没有覆盖工具?

Any ideas how I can set up my build so that I get the same test results with or without a coverage tool ?

请注意:这个问题最初发布的认为这是与TeamCity的一个问题,但它不是

NOTE: This question was initially posted believing that it was a problem with TeamCity but it is not.

推荐答案

我认为主要问题在这里是<一个href="http://blogs.msdn.com/b/clr$c$cgeneration/archive/2009/05/11/tail-call-improvements-in-net-framework-4.aspx"相对=nofollow>尾部调用优化,当编译器崩溃堆栈帧来提高性能。这种情况只有在释放模式。

I believe that the main issue here is Tail call optimization, Where the compiler collapses stack frames to boost performance. This happens only in Release mode.

dotCover(其它.NET廓)禁止某些CLR的优化,preventing妥协的结果 - 这将是很难计算的方法执行,如果他们不执行......

dotCover (as other .net profilers) disables some of the CLR's optimizations, preventing compromised results - It would be hard to count method executions if they don't execute...

我不能告诉你,如果NCover无法克服的优化,或解决了这个以另一种方式,但我很肯定dotCover。

I can't tell you if NCover fails to overcome the optimizations, or solves this in another way, but i'm quite sure about dotCover.

这篇关于使用dotCover不一致时,测试结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆