【问题标题】:While running the MVC4 unit test case in VS 2012 getting error An exception occurred while invoking executor 'executor://mstestadapter/v1':在 VS 2012 中运行 MVC4 单元测试用例时出现错误调用执行程序“executor://mstestadapter/v1”时发生异常:
【发布时间】:2013-03-23 13:04:55
【问题描述】:

在 VS 2012 中尝试在 MVC4 中运行我的单元测试用例时,出现错误:-

调用执行程序“executor://mstestadapter/v1”时发生异常:对象引用未设置为对象的实例。

我搜索了很多,大部分答案是实体框架 dll,但我没有使用实体框架。

我在 MVc3 中创建了单元测试用例,最近,我们转换为 MVC4。但我不确定这是因为我团队中的其他人能够运行他们的测试用例。

任何帮助将不胜感激。

【问题讨论】:

    标签: unit-testing visual-studio-2012


    【解决方案1】:

    只需在您的测试mentod 类中使用以下方法即可。

        [TestCleanup]
        public void TestCleanup()
        {
            //Clear you object here. whatever in error message.
            OperationContext.OperationContext.Clear();
        }
    

    我也遇到过这种问题,加了这个功能后就可以了。

    【讨论】:

    • 感谢 Gurpreet 的回复。一个简单的问题 - 我还需要添加 OperationContext 吗?它似乎存在于与 WCF 相关的 System.ServiceModel 命名空间中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 2015-11-21
    • 2017-07-21
    相关资源
    最近更新 更多