Bob*_*orn 7 c# debugging mstest visual-studio-2012
编辑:我刚刚尝试使用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);
}
Run Code Online (Sandbox Code Playgroud)
反汇编仅显示实际受到影响的代码行.

现在,看看这个.如果我添加一行新代码,调试器会识别它,并且其他代码行会发生变化,只要调试器能够识别.在方法中,第二行代码是新的.
[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);
}
Run Code Online (Sandbox Code Playgroud)
这是反汇编的部分快照,显示了新的代码行:

怎么会发生这种情况?
更奇怪的是,这一点甚至回归:
if (DateTime.Now > DateTime.Now.AddDays(1)) { return; }
Run Code Online (Sandbox Code Playgroud)
我尝试过的事情:
- 从硬盘删除源代码并强制获取最新版本
- 修复VS 2012
- 做一些VS 清理
- 使用VS 2010,更改代码,签入,获取VS 2012的最新版本
- 重启
- 其他(不记得所有这些)
小智 4
这似乎是特定于单元测试的。在VS 2012中:
请注意,我有机会访问源代码,并且下载了 Presto ( http://presto.codeplex.com/ )。
| 归档时间: |
|
| 查看次数: |
942 次 |
| 最近记录: |