Nunit tests with MvcApprovals Verify specific url

234 Views Asked by At

the project url of my mvc application is hosted like this localhost:port/AppName

I created a new unit test project to test the mvc app using nunit framework and for approval tests I used 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 throws an error saying that it couldn't find the url since I didn't set the right project url :

The Following error occurred while connecting to:

http: // localhost: 8080/ Scope / _index

error:

The remote server returned an error: (404) Not Found.

So my question is how to set the right url to set with nunit for mvc approval test

1

There are 1 best solutions below

0
On

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