【问题标题】:Unable to debug unit test cases using fakes无法使用假货调试单元测试用例
【发布时间】:2015-10-06 07:12:35
【问题描述】:

我在

中使用单元测试项目以及 MS Fakes 模拟框架

Visual Studio Premium 2013 更新 4

。当我在 Visual Studio 中运行测试时它工作正常,但是当我尝试调试单元测试用例时它失败并出现以下错误:

Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: 无法从 COR_PROFILER_PATH 解析探查器路径和 COR_PROFILER 环境变量。

我尝试过的以下方法:

  1. 特定版本为 false [未工作]
  2. 删除所有假货、清理、构建和读取 [未工作]
  3. 添加了 System and mscorlib fakes [Not working]

编辑:

[TestMethod]
public void LoginResponseTest()
{
    using (ShimsContext.Create())//Getting error here in case of debug test
    {

      var stub = new StubISimpleHttpService();
      stub.SendPostRequestStringParameterCollection = GetLoginResponse;
      MyAPIConnector connector = new MyAPIConnector();
      uint response = connector.login("test_username", "test_password");

      Assert.IsTrue(response == 0);                
    }    
}

有什么解决办法吗?

【问题讨论】:

  • 我怀疑是否有人能够根据这篇文章的知识重现此错误。请提供MCVE
  • 你是如何调试测试的?您是否使用任何第三方工具,例如 Jetbrains Resharper 测试运行器?在我厌倦了使用 Resharper 调试包含 MS Fakes 的单元测试之前,我已经看到过这个错误。
  • 否,VS3013提供的默认单元测试
  • 出于好奇,尝试以管理员身份运行 Visual Studio,然后尝试调试测试?这有什么区别吗?

标签: c# unit-testing visual-studio-2013 microsoft-fakes


【解决方案1】:

我已将需要存根的接口添加到假货的设置中。例如:

<StubGeneration>
  <Clear/>
  <Add Interfaces="true" FullName="ISimpleHttpService"/>
</StubGeneration>
<ShimGeneration>
  <Clear/>
  <Add FullName="HttpResponse"/>
</ShimGeneration>

解释: 我们只需要添加那些被单元测试假货使用的假货 dll。我们需要将 StubGeneration 标签添加到 xml 文件中。这些标签取决于单元测试用例使用的类。

【讨论】:

  • 请解释一下您是如何发现的,我在这里遇到了同样的问题,并且有很多假类型要检查。
  • @MarcusVinicius:我在回答中添加了解释。请调查一下。如果它不能解决您的问题,请添加错误详细信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-11
  • 1970-01-01
  • 2021-05-09
  • 2023-03-27
  • 1970-01-01
相关资源
最近更新 更多