Search code examples
c#asp.net-mvcunit-testingvalidation

Testing ASP.NET MVC views for valid HTML


As part of our build process, we want to be able to run a bunch of unit tests against our ASP.NET MVC views to ensure they're emitting valid HTML.

We don't want to unit test the views per se, we just want to test that the output being generated by the views is standards compliant HTML.

I'm wondering if anyone has any suggestions on how we might be able to achieve this as part of an automated set of tests?

The unit tests might look something like this (this is just sample code and doesn't compile but gives an idea of what I would like to do):

[Test]
public void TestSomeViewHtml
{
    //get the html generated from the view
    string viewHtml = RenderView("someView");

    //Magic html validator that I don't know about yet but hoping the stackoverflow guru's can point me in the right direction to
    Assert.IsTrue(HtmlValidator.IsValidHtml(viewHtml));
}

Solution

  • You can try TidyManaged which is a .net wrapper around Tidy.