7

编辑:我刚刚在 VS 2010 上试过这个,问题没有发生。这个问题只发生在 VS 2012 上。这真的是一个错误吗?这也发生在我的两台单独的笔记本电脑上,甚至在朋友的笔记本电脑上(刚刚获得最新代码)。

首先,问题的截图。这个方法是全新的代码。

在此处输入图像描述

调试器正在跳过我最近签到的代码。下面代码中的注释解释了我调试此方法时发生的情况。所以真的没有必要去尝试理解代码;请注意,正在跳过代码行。如果您认为代码与正在调试的程序集不匹配,请多多包涵。您将看到调试器在哪里识别新代码,但不识别现有代码。这种行为发生在两台不同的笔记本电脑上,在删除磁盘上的代码并再次获取最新版本之后。每条注释都会告诉您调试器是否命中了一行。

[TestMethod()]
[DeploymentItem("PrestoCommon.dll")]
public void ApplicationShouldBeInstalledTest_UseCase9()
{
    // Debugger hits this line
    ApplicationServer appServerAccessor = new ApplicationServer();

    // Debugger does not hit these next two lines
    PrivateObject privateObject = new PrivateObject(appServerAccessor);
    ApplicationServer appServer = ApplicationServerLogic.GetByName("server10");

    // Debugger hits this line. Weirdness: both objects are null, and after this line runs,
    // appServerAccessor is no longer null.
    appServerAccessor.Id = appServer.Id;

    // Skips this line
    ApplicationWithOverrideVariableGroup appWithValidGroup = appServer.ApplicationsWithOverrideGroup[0];

    // Debugger hits this line, but F11 doesn't take me into the method.
    appWithValidGroup.CustomVariableGroup = CustomVariableGroupLogic.GetById("CustomVariableGroups/4");

    // Skips this line
    Assert.AreEqual(true, true);
}

反汇编只显示实际受到影响的代码行。

在此处输入图像描述

现在,检查一下。如果我添加新的代码行,调试器会识别它,并且其他代码行会更改,只要被调试器识别。只是方法中的第二行代码是新的。

[TestMethod()]
[DeploymentItem("PrestoCommon.dll")]
public void ApplicationShouldBeInstalledTest_UseCase9()
{
    // Debugger hits this line
    ApplicationServer appServerAccessor = new ApplicationServer();

    // New line. It's recognized by the debugger, and it shows up in the disassembly.
    if (DateTime.Now > DateTime.Now.AddHours(1)) { return; }

    // Debugger does not hit these next two lines
    PrivateObject privateObject = new PrivateObject(appServerAccessor);
    ApplicationServer appServer = ApplicationServerLogic.GetByName("server10");  // Gets hit now.

    // Debugger hits this line. Weirdness: both objects are null, and after this line runs,
    // appServerAccessor is no longer null.
    appServerAccessor.Id = appServer.Id;  // No longer gets hit.

    // Skips this line (now it's getting hit)
    ApplicationWithOverrideVariableGroup appWithValidGroup = appServer.ApplicationsWithOverrideGroup[0];

    // Debugger hits this line, but F11 doesn't take me into the method. Now this gets skipped.
    appWithValidGroup.CustomVariableGroup = CustomVariableGroupLogic.GetById("CustomVariableGroups/4");

    // Skips this line. Still skipped.
    Assert.AreEqual(true, true);
}

这是反汇编的部分快照,显示了新的代码行:

在此处输入图像描述

这怎么可能发生?

更奇怪的是,在某一时刻,这甚至返回了:

if (DateTime.Now > DateTime.Now.AddDays(1)) { return; }

我尝试过的事情:
- 从硬盘驱动器中删除源代码并强制获取最新版本
- 修复 VS 2012
- 进行一些 VS清理
- 使用 VS 2010,更改代码,签入,使用 VS 2012 获取最新版本
- 重新启动
- 其他(不记得全部)

4

1 回答 1

4

这似乎是特定于单元测试的。在 VS 2012 中:

  • 测试 > 测试设置
  • 打开选定的测试设置文件
  • 数据和诊断 > 取消选择代码覆盖率 (Visual Studio 2010)
  • 申请

注意,我有访问源代码的优势,我下载了 Presto ( http://presto.codeplex.com/ )。

于 2013-02-15T18:17:43.190 回答