【问题标题】:VS2015 Unit test project is unable to find a methodVS2015 单元测试项目找不到方法
【发布时间】:2016-07-21 04:39:34
【问题描述】:

我收到此错误:

结果堆栈跟踪:在 UnitTestProject.ControllerTest.TestMethodQuoteEndCustomerSearch() 结果消息:测试方法 UnitTestProject.ControllerTest.TestMethodQuoteEndCustomerSearch 抛出 异常:System.MissingMethodException:找不到方法: 'System.Web.Mvc.ActionResult QuoteCenter.Controllers.ECSearchController.QuoteEndCustomerSearch(System.String, System.String, System.String, System.String)'。

我的测试类如下所示:

namespace UnitTestProject
{
    [TestClass]
    public class ControllerTest
    {
        [TestMethod]
        public void TestMethodQuoteEndCustomerSearch()
        {
        //arrange
        ECSearchController myController = new ECSearchController();           

        //ISSUE WITH THE NEXT LINE
        ViewResult result = myController .QuoteEndCustomerSearch("", "", "", "") as ViewResult;
        }
    }
}

智能感知知道 myController 有一个方法 QuoteEndCustomerSearch。但是当我调试时,我得到了上述错误。

控制器的方法如下所示:

[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
    public ActionResult QuoteEndCustomerSearch(String quoteId, String CID, String URL, String UserID)
    { 
        //...
        return View("QuoteEndCustomerSearch", model);
    }

关于我还应该尝试什么使其正常工作的任何提示?我处于管理员模式,我已经重新启动了 VS2015。

【问题讨论】:

  • 如果视图与操作同名,则无需将其包含在View() 中。更改return View("QuoteEndCustomerSearch", model); 以返回视图(模型);
  • 感谢 Nkosi 的有用提示

标签: c# debugging testing visual-studio-2015 method-missing


【解决方案1】:

问题是我现有的项目有 mvc 版本 5,但新的测试项目有一个更新的版本。现在一切都好。 当我使用 Nuget 时,我没有注意到版本不同。 我认为现在是我将所有项目更新到最新版本的 MVC 的好时机。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    相关资源
    最近更新 更多