Using Razorgenerator to Unit Test view views

Source: Internet
Author: User

In ASP., we can easily unit test model and controller controllers, but for

The testing of view views is not so easy and straightforward. Here is a way to use Razorgenerator to

Unit tests.

Nonsense not much to say directly. The main methods and steps are as follows:

1. Create an ASP. NET MVC project and the corresponding test project.

2. Add the package to NuGet in the Web project: Razorgenerator.msbuild.

3. NuGet Add package in test project: razorgenerator.testing; add Package NUnit

4. Modify the code you want to test in a Web project views\shared\error.cshtml

@model system.web.mvc.handleerrorinfo@{    viewbag.title = "Error";} <div id= "Content" >    

5. Add test code to the Web test project

Using system;using system.linq;using system.web.mvc;using htmlagilitypack;using nunit.framework;using        Razorgenerator.testing;namespace webapplication1.tests.views.shared{[testfixture] public class ErrorTest1 { [Test] public void TestMethod1 () {asserthtml<asp._views_shared_error_cshtml, Handleerrorin Fo> ("Content", @ "

6, run the test, test pass.

Using Razorgenerator to Unit Test view views

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.