1

I created a Unit Test project using Visual Studio 2013 Express for Web.

and my test is this

    [TestMethod]
    public void it_should_return_the_home_view()
    {
        // arrange
        HomeController controller = new HomeController();

        // act
        ViewResult result = controller.Index() as ViewResult;

        // assert
        Assert.IsTrue(string.IsNullOrEmpty(result.ViewName));
    }

My HomeController has this action method:

    public ActionResult Index()
    {
        ViewBag.Message = "Welcome!";
        return View();
    }

When I run the test above an exception occurs at "return View()"

The exception message is "An exception of type 'System.TypeInitializationException' occurred in System.Web.Mvc.dll"

1 Answer 1

2

Had same error. So I referenced this assembly in my unit test project System.Web.WebPages.dll.

If you create MVC project with VS default template and check to add unit test project all necessary references are included.

For empty unit test projects targeting MVC 5 project best solution is to add mvc5 via nuget as suggested here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.