Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 使用方法在垫片内的摩尔中插入_C# 4.0_Visual Studio 2012_Automated Tests_Moles - Fatal编程技术网

C# 4.0 使用方法在垫片内的摩尔中插入

C# 4.0 使用方法在垫片内的摩尔中插入,c#-4.0,visual-studio-2012,automated-tests,moles,C# 4.0,Visual Studio 2012,Automated Tests,Moles,最近,在浏览一个项目的自动化测试用例时,我遇到了一段类似这样的代码 [TestMethod] public void UpdateTtWebScResearchIdt() { using (ShimsContext.Create()) { // Some code SomeNamespace.Moles.MSubCom.StringFormatStringStringArray = (x, y) =&

最近,在浏览一个项目的自动化测试用例时,我遇到了一段类似这样的代码

[TestMethod]
    public void UpdateTtWebScResearchIdt()
    {
        using (ShimsContext.Create())
        {
            // Some code
            SomeNamespace.Moles.MSubCom.StringFormatStringStringArray = (x, y) => "gLibErr";                
            //Assert
        }
    }
调试此测试方法时,编译器显示以下错误

分子有效操作异常

在摩尔法被截断的线路上,即

SomeNamespace.Moles.MSubCom.StringFormatStringStringArray = (x, y) => "gLibErr";
详细信息显示了这一点

“Moles要求在仪器化过程中进行测试。 在Visual Studio单元测试中,向单元测试方法添加以下属性:

添加此属性

[TestMethod]        
[HostType(Moles)]      
public void Test()     
{ 
... 
}
大多数单元测试框架也可以使用扩展。请参阅Moles手册

但是添加上述属性也不能解决我的问题

我认为在加垫片的方法中使用摩尔是有问题的。 我需要另一种意见(或许多意见)。 如果有人能提出解决方案那就太棒了


谢谢。

初始代码的唯一问题是缺少
[HostType(Moles)]
。接下来,您必须确保您正在使用Visual Studio测试运行程序运行测试。如果您安装了其他测试运行程序,则可能是它没有加载Moles主机


我找不到为什么它是这样写的,所以我使用fakes assembly重写了整个测试方法。现在它运行良好。

感谢响应对等方。正如我已经提到的,添加属性不起作用。在将方法指定为Moles host时,ShimsContext.Create()出现类似异常时中断。您使用的是什么testrunner?Visual Studio Test Runner