0

我的 mvc 应用程序的项目 url 像这样托管 localhost:port/AppName

我创建了一个新的单元测试项目来测试 mvc 应用程序使用 nunit 框架和批准测试我使用了 Approval Tests Library

[Test]
    [UseReporter(typeof(FileLauncherReporter),typeof(ClipboardReporter))]
    public void PaymentPopUpController_IndexView()
    {
        //Arrange
        PortFactory.MvcPort = 8080;
        // Act      
        Func<ActionResult> ScopeControllerTest = new ScopeController()._Index;

        // Approve
        MvcApprovals.VerifyMvcPage(ScopeControllerTest);
    }

MvcApprovals.VerifyMvcPage 抛出一个错误,说它找不到 url,因为我没有设置正确的项目 url:

连接到时出现以下错误:

http://localhost:8080/Scope/_index

错误:

远程服务器返回错误:(404) Not Found。

所以我的问题是如何设置正确的 url 来设置 nunit 进行 mvc 批准测试

4

1 回答 1

0

MvcApprovals will construct the url from the combination of the Controller name + the Method name. So in this case the new ScopeController()._Index is being translated to Scope/_Index

There are 2 possibilities as to why this isn't working

1) Bad url. Possibly the _index isn't public or otherwise isn't the correct route. The easiest way to test this is simply to open a web browser and point it at

http://localhost:8080/Scope/_index

If your browser can't see this url then neither can approvaltests. (unless you are using cassinidev)

2) The second reason is you might not have the web server turned on during the test. This would also be shown by opening the url in a browser.

Happy Testing!

Llewellyn Falco

于 2015-01-08T09:00:52.670 回答